The following code:
Base = declarative_base()
engine = create_engine(r\"sqlite:///\" + r\"d:\\foo.db\",
listeners=[ForeignKeysListener()])
This is because you are trying to access bar
from the FooBar
class rather than a FooBar
instance. The FooBar
class does not have any bar
objects associated with it--bar
is just an sqlalchemy InstrumentedAttribute. This is why you get the error:
AttributeError: Neither 'InstrumentedAttribute' object nor 'Comparator' object associated with FooBar.bar has an attribute 'foo'
You will get the same error by typing FooBar.bar.foo.name
outside the sqlalchemy query.
The solution is to call the Foo
class directly:
ses.query(FooBar).join(Bar).join(Foo).filter(Foo.name == "blah")