I tried create_instance event and it fires, now having: def see_what_type(mapper, context, row, class_): if **is_air**: return Air() else: return EXT_CONTINUE
def initialize_sql(engine): ... layer_mapper = mapper(Layer, layers) mapper(Air, inherits=layer_mapper) ... event.listen(Layer, 'create_instance', see_what_type, retval=True) and setting **is_air** as True I get Air instances querying for Layer with filled attributes and relationships. I don't know about other caveats... Now I have to find a robust way to check id_type (one of `row` items) in see_what_type. Any advice? Thanks for your support On Fri, Jul 29, 2011 at 12:15 AM, Michael Bayer <mike...@zzzcomputing.com>wrote: > > On Jul 28, 2011, at 6:08 PM, neurino wrote: > > Thanks Michael, > > my need is quite easy, no need of complex querying. > > Simply my class represents a Layer and, while quite all layer types > (concrete, wood, bricks, etc.) act the same, only one (air) acts in a > completely different way. > > With "act" I refer to performing calculations on float attributes, no more. > > So I can simply put in all calc functions separate operations: > > if self.type == air: > #air calcs > else: > #all others calcs > > or, in a more elegant way, use a Layer subclass named Air. > > I can't create subclasses for all other layers since I don't know them in > advance. > > As far as I understand I have to go with first solution at the moment, > right? > > > probably, there's an old event for this called create_instance (1) that was > meant for this a long time ago but I don't know what kinds of caveats it has > with modern usage. polymorphic_on=callable is ticket #1131 (2), note it is > very old and the code examples there are out of date. > > > 1: > http://www.sqlalchemy.org/docs/orm/events.html#sqlalchemy.orm.events.MapperEvents.create_instance > 2: http://www.sqlalchemy.org/trac/ticket/1131 > > > > > On Thu, Jul 28, 2011 at 11:38 PM, Michael Bayer > <mike...@zzzcomputing.com>wrote: > >> column_property() > > > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to sqlalchemy@googlegroups.com. > To unsubscribe from this group, send email to > sqlalchemy+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/sqlalchemy?hl=en. > > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to sqlalchemy@googlegroups.com. > To unsubscribe from this group, send email to > sqlalchemy+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/sqlalchemy?hl=en. > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.