0

给定以下模型:

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 实例

4

1 回答 1

0

取一组查询返回的结果。object默认情况下,返回的s 是可散列的,因此该set函数可以区分两个 Foo object,并确保您输入q的内容实际上是不同的。

于 2013-05-23T06:54:20.980 回答