我有两个课程,TrialIdentifier
和TimeCourse
TimeCourse有一个包含TrialIdentifier的实例变量,我试图在两者之间建立外键关系。
__tablename__ = 'trial_identifiers'
relationships = relationship('TimeCourse',
back_populates = 'trial_identifier', uselist = False)
在TimeCourse中
__tablename__ = 'time_course'
trial_identifier_id = Column(Integer, ForeignKey('trial_identifiers.id'))
trial_identifier = relationship('TrialIdentifier', back_populates = 'relationships')`
如果我在trial_identifier
中命名变量TimeCourse
,则会引发以下错误:
sqlalchemy.exc.InvalidRequestError: Mapper 'Mapper|TimeCourse|time_course' has no property 'trial_identifier'
如果我将其他名称命名,一切正常。整个包都是基于TimeCourse().trial_identifier
构建的,所以我希望尽可能避免重构。或至少了解这种行为。
答案 0 :(得分:3)
trial_identifier是一个私有变量,定义为trial_identifier = relationship('TrialIdentifier', back_populates = 'relationships')`
删除setter和getter,或替换
_trial_identifier = relationship('TrialIdentifier', back_populates = 'relationships')`
与
A a = new A();
a->fun1("one");
a->fun2(1, 2);
...
a->fun10("end");
解决了问题