0
我有這些模型:引發ArgumentError在joinedload
class User(UserMixin, db.Model):
__tablename__ = 'users_user'
...
country = db.Column(db.Integer, db.ForeignKey('countries.id'))
class Country(db.Model):
__tablename__ = 'countries'
id = db.Column(db.Integer, primary_key=True)
...
user_country = db.relationship('User', backref='user_country', lazy='joined')
我想這個查詢:
User.query.options(joinedload(Country.user_country)).filter_by(id=current_user.get_id()).first()
這將引發此錯誤:
ArgumentError: Can't find property 'user_country' on any entity specified in this Query.
Note the full path from root (Mapper|User|users_user) to target entity must be specified.
什麼是錯的這裏?
爲什麼不使用'current_user.user_country'? – dirn 2014-11-06 01:42:02