我有一组像这样定义的类:
class CrosstabCohort(Base):
__table__ = crosstab_cohorts
# has property is_column
cohort = relationship(Cohort, innerjoin=True)
class Crosstab(Base):
__table__ = crosstabs
columns = relationship(CrosstabCohort,
#secondary=crosstab_cohorts,
primaryjoin=and_(
crosstabs.c.crosstab_id == crosstab_cohorts.c.crosstab_id,
crosstab_cohorts.c.is_column == True),
order_by=crosstab_cohorts.c.created_at,
)
rows = relationship(CrosstabCohort,
#secondary=crosstab_cohorts,
primaryjoin=and_(
crosstabs.c.crosstab_id == crosstab_cohorts.c.crosstab_id,
crosstab_cohorts.c.is_column == False),
order_by=crosstab_cohorts.c.created_at,
)
当我通过调用关系实例上的append
添加列或行对象时,我希望is_column
属性自动设置为True
或{{1}取决于我追加它的关系。这可能吗?目前,当我附加到这些关系并尝试提交时,我从数据库收到一个错误,即未设置False
属性。这可以自动完成,还是必须在每个is_column
对象上设置is_column
属性?