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