Firstly, thanks for making this software available.
My question is related to this issue, probably a common one for newbies :
Consider the following entities :
__tablename__ = "foo"
id = Column(Integer, primary_key=True)
name = Column(String, unique = True)
__tablename__ = "bar"
id = Column(Integer, primary_key = True)
foo_id = Column(Integer, ForeignKey("foo.id"))
foo = relationship("Foo", lazy="joined")
ses.query(Bar).filter(Bar.foo.name == "blah") throws
AttributeError: Neither 'InstrumentedAttribute' object nor 'Comparator'
object associated with Bar.foo
has an attribute 'name'
( Note : i have edited the example somewhat )
>From the answers, it seems that i cannot use Bar.foo.name, since foo is a
Also, i have to explicitly join Foo to the query in order to use its attributes
in filter or order-by.
However, when i do this, and i have lazy="joined" in the relationship,
the relation too creates a join (which cannot be used in the filter, orderby),
plus the join i have already added in the query.
My questions are related to this :
1. Why don't we allow the declared relations to be available in the query for
filter/order-by etc ?
Does this not undermine the power of declarative relations ?
Can we declare a list of columns to be fetched for a relation ?
2. Given that we might have to add filter conditions to queries over time, what
is the best-practice for loading
declared relations ? Should they have lazy="noload" or default(lazy-loading)
and we use explicit joins in queries to avoid the duplicate joins ?
3. If i add a filter in the query for Foo without creating a join, it adds Foo
in the FROM clause,
but without any join condition.
Is this a bug ?
The Python SQL Toolkit and Object Relational Mapper
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
You received this message because you are subscribed to the Google Groups
To unsubscribe from this group and stop receiving emails from it, send an email
To post to this group, send email to firstname.lastname@example.org.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.