鉴于以下模型:
class Foo(db.model):
id = db.Column(db.Integer, primary_key=True)
bar_id = db.Column(
"bar_id",
db.Integer(),
db.ForeignKey("bar.id"))
baz_id = db.Column(
"baz_id",
db.Integer(),
db.ForeignKey("baz.id"))
bars = db.Relationship(
"Bar",
backref=backref("bar_foo", lazy="dynamic"))
bazs = db.relationship(
"Baz",
backref=backref("baz_foo", lazy="dynamic"))
class Bar(db.model):
id = db.Column(db.Integer, primary_key=True)
# some more columns
class Baz(db.model):
id = db.Column(db.Integer, primary_key=True)
# some more columns
q = Bar.query.get(123).bar_foo
# .all() gives me several Foo instances
我想为q结果检索不同的Baz实例
答案 0 :(得分:0)
获取查询返回的一组结果。默认情况下,object
返回的是 hashable ,因此set
函数可以将两个Foo object
区分开,并确保您在{{1}中获得的内容实际上是截然不同的。