I'm sure this is something fairly basic, but I'm stumped at this point. I have a single table inheritance scheme setup very similar to this:
class SimpleType(object): def __init__(self, type='base_type', name='base_type'): self.type = type self.name = name class AddressType(SimpleType): type = 'Address' def __init__(self, name): SimpleType.__init__(self, 'Address', name) class ContactType(SimpleType): type = 'Contact' def __init__(self, name): SimpleType.__init__(self, 'Contact', name) types_table = Table('types', metadata, Column('type' , String(20), primary_key=True), Column('name' , String(20), primary_key=True) ) mapper(SimpleType, self.types_table, polymorphic_on=self.types_table.c.type, polymorphic_identity='base_type') mapper(AddressType, self.types_table, inherits=types_mapper, polymorphic_identity='Address') mapper(ContactType, self.types_table, inherits=types_mapper, polymorphic_identity='Contact') My question is about querying. Is the expected behaviour of "session.query(AddressType)" to return all values from the 'types' table? (i.e. for me this returns all AddressType and ContactType values from the table)? If so, is there a standard or preferred method of getting just those values associated with one class without hardcoding the classes polymorphic_identity value into the query? For instance, "session.query(AddressType).filter_by(type='Address')" works, but "session.query(AddressType).filter_by (type=AddressType.type)" does not. I'd really like to wrap up this type of query in a simple call to the class type. Any suggestions greatly appreciated. Thanks, Mark --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---