Martin Stein wrote:
> Hi everybody,
>
> In my db-setup, there is a one-to-many relationship with a backref that is
> configured for eager loading (not the relation but the backref!). When I
> access the child objects of the parent object, the query from sqlalchemy
> joins back to the parent object (due to eager loading). In this case, the
> join is unnecessary, since the parent object is already known.
>
> Is there something I am missing or a way to avoid the join?

Ok that's kind of interesting.   as a general rule, the ORM doesn't like
to make assumptions.  such as here, there is a lazyloader on
User.keywords, which says "query for these Keyword objects", without any
knowledge of what that query is.   the keywords.user attribute has an
eager load on it so it just does what it's told.  In this case, the idea
would be User.keywords knows that its one-to-many and that the backref is
many-to-one, and additionally that the many-to-one load is "simple", i.e.
uses just a get(), and then sends a lazyload(Keyword.user) to the query.

its an interesting idea which wouldn't be so hard to implement, although
my nervousness would be about unforeseen side effects.  feel free to file
an enhancement ticket for it.

in the short term, I would recommend just not using lazy=False, in favor
of eagerload() for queries where you know you'll want to descend that
deeply.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to