型号:
class Thing(db.Model):
__tablename__ = 'things'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(128))
type_id = db.Column(db.Integer, db.ForeignKey('types_of_things.id'))
class TypeOfThing(db.Model):
__tablename__ = 'types_of_things'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(64))
number = db.Column(db.Integer)
things = db.relationship('Thing', backref='type', lazy='dynamic')
尝试:
Thing.query.join(TypeOfThing).filter_by(Thing.type.number<=1).first()
原因:
AttributeError:既没有'InstrumentedAttribute'对象也没有 与Thing.type关联的“Comparator”对象具有属性 '编号'
尝试:
Thing.query.join(TypeOfThing).filter_by(number<=1).first()
原因:
NameError:未定义名称'number'
答案 0 :(得分:1)
似乎我需要这样做:
Thing.query.join(TypeOfThing).filter(TypeOfThing.number<=1).first()