I have three models with inheritance and relationship and I want to cache query to this models.
class Person(Base):
__tablename__ = 'person'
id = Column(Integer, primary_key=True)
name = Column(String(100), nullable=False)
type = Column(String(50))
__mapper_args__ = {
'polymorphic_identity': 'object',
'polymorphic_on': type
}
class Man(Person):
__tablename__ = 'man'
id = Column(Integer, ForeignKey('person.id'), primary_key=True)
age = Column(String(100), nullable=False)
__mapper_args__ = {'polymorphic_identity': 'man'}
class Config(Base):
__tablename__ = "config"
id = Column(Integer, primary_key=True)
person = Column(Integer, ForeignKey('person.id'))
address = Column(String)
person_ref = relationship(Person)
There are a lot of others models inherited from Personal. For example I need to get access to Man attributes through Config relationship. Normally I would do:
config = session.query(Config).join(Config.person_ref).filter(Person.type == 'man').first()
print config.person_ref.age
How can I cache query like this with dogpile? I can cache query to Config, but I can't cache query to attributes of Man, emits SQL every time. I tried to use with_polymorphic, but it's only works without joinedload. (don't undestand why)
config = session.query(Config).options(FromCache("default")).first()
people = session.query(Person).options(FromCache("default")).with_polymorphic('*').get(config.person)
but I need joinedload to filter for types.