Các mã sau đây:AttributeError khi truy vấn: đối tượng Cả 'InstrumentedAttribute' cũng không 'sánh' có một thuộc tính
Base = declarative_base()
engine = create_engine(r"sqlite:///" + r"d:\foo.db",
listeners=[ForeignKeysListener()])
Session = sessionmaker(bind = engine)
ses = Session()
class Foo(Base):
__tablename__ = "foo"
id = Column(Integer, primary_key=True)
name = Column(String, unique = True)
class Bar(Base):
__tablename__ = "bar"
id = Column(Integer, primary_key = True)
foo_id = Column(Integer, ForeignKey("foo.id"))
foo = relationship("Foo")
class FooBar(Base):
__tablename__ = "foobar"
id = Column(Integer, primary_key = True)
bar_id = Column(Integer, ForeignKey("bar.id"))
bar = relationship("Bar")
Base.metadata.create_all(engine)
ses.query(FooBar).filter(FooBar.bar.foo.name == "blah")
được đem lại cho tôi lỗi này:
AttributeError: Neither 'InstrumentedAttribute' object nor 'Comparator' object associated with FooBar.bar has an attribute 'foo'
Bất kỳ giải thích, là tại sao này đang xảy ra, và hướng dẫn làm thế nào một điều như vậy có thể đạt được?
Điều gì sẽ xảy ra nếu bảng có nhiều mối quan hệ với 'Foo' ? –