SQLAlchemy newbie here.
I'm trying to define a model (subclassed by another model) that represents a subset of table data of the parent model. Specifically, I want the subclass to map the most recent row for a given ID.
For example, suppose I have the following model:
class AddressHistory(Base):
__table__ = 'address_table'
date = Column(Date, index=True, nullable=False)
id = Column(BigInteger, primary_key=True)
street = Column(String(2000))
city = Column(String(2000))
state = Column(String(2000))
zip = Column(Integer)What I want to do is define a subclass of this model which represents the most recent address record:
class MostRecentAddress(Address):
“””
Represents a row in AddressHistory with the most recent date for a given id.
”””Is there some sort of subquery I can pass to the mapper_args ? Maybe a polymorphic_identity? Or could I create a separate view and have the subclass read from that?
Thanks!
Thanks!
--
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+...@googlegroups.com.
To post to this group, send email to sqlal...@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
class _AddressMixin(object): date = Column(Date, index=True, nullable=False) id = Column(BigInteger, primary_key=True) street = Column(String(2000)) city = Column(String(2000)) state = Column(String(2000)) zip = Column(Integer)
class AddressHistory(Base, _AddressMixin): __table__ = 'address_table'
class MostRecentAddress(Base, _AddressMixin): __table__ = 'address_table'