有模型。
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 对象或者是不可能做的,只需添加两个的结果查询?