我已经定义了这些一对一模型,我正在尝试在parent.method1
内调用child.call_parent_method
class Parent(db.Model):
__tablename__ = 'parent'
id = db.Column(db.Integer, primary_key=True)
child = db.relationship('Child', backref='parent')
child_id = db.Column(db.Integer, db.ForeignKey('child.id'),
nullable=True)
@hybrid_property
def prop1(self)
print 'This is method 1'
class Child(db.Model):
__tablename__ = 'child'
id = db.Column(db.Integer, primary_key=True)
def call_parent_method(self):
self.parent.prop1
但是我得到的是:
AttributeError: 'InstrumentedList' object has no attribute 'prop1'