モデルがあります。
class CMiixin(objects):
@declared_attr
def x(cls):
return Column(Float)
class ABase(Base):
__tablename__ = 'a_base'
@declared_attr
def __mapper_args__(cls):
return {'polymorphic_identity': '%s' % cls.__tablename__,
'polymorphic_on': cls.type,
'with_polymorphic': '*'}
id = Column(Integer, primary_key= True)
type = Column(String)
# other attr
class A(CMixin, ABase):
__tablename__ = 'a'
id = Column(ForeignKey('a_base.id'), primary_key= True)
# other attr
class BBase(Base):
__tablename__ = 'b_base'
@declared_attr
def __mapper_args__(cls):
return {'polymorphic_identity': '%s' % cls.__tablename__,
'polymorphic_on': cls.type,
'with_polymorphic': '*'}
id = Column(Integer, primary_key= True)
type = Column(String)
# other attr
class B(CMixin, ABase):
__tablename__ = 'b'
id = Column(ForeignKey('b_base.id'), primary_key= True)
# other attr
x(attribute CMixin) <= 5で単一のクエリAとBを選択する方法は? 何かこの db.session.query(???).filter(Ax <= 5, Bx <= 5).all() 結果リストを A と B のオブジェクトにするか、それとも不可能で、2 つの結果を加算するだけですかクエリ?