Ok, I've only put one() here for an example. I saw the query, there is no 
LIMIT. And it selects only filtered results, as i wanted.
 But I' m still unsure if i get it right about how SQLalchemy treat 
contains_eager-does it load data for mentioned relationships only from query 
which we declare this option to?

Отправлено с моего Андроида

-----Original Message-----
From: Michael Bayer <mike...@zzzcomputing.com>
To: sqlalchemy@googlegroups.com
Sent: сб, 31 янв 2015 20:51
Subject: Re: [sqlalchemy] Is it possible to populate relationship's collection 
with only query-filtered results using contains_eager()?



Юрий Пайков <dia...@cry5tal.in> wrote:

> When I do a query like this
> 
> result = session.query(A).\
> join(A.bs).\
> join(B.cs).\
> filter_by(C.somedata.in_([4455, 4466])).\
> options(contains_eager(A.bs).contains_eager(B.cs)).one()
> 
> and list related C objects
> 
> for b in result.bs:
>    b.cs
> 
> I get all related to B C objects instead of only those with 4455, 4466 values 
> - even though I filtered the output of the statement.


turn on echo=True that will show what SQL is being emitted.      That one() 
might be adding a LIMIT to the query that you don’t want, and the 
contains_eager() might be failing to connect to the collections, and thus they 
are lazy loaded after the fact.





> 
> So eager loading when used with contains_eager() - as I understand - 
> shouldn't load other related objects apart from those which are selected by 
> statement. Still I get Cs with values other that 4455, 4466(i.e. all the 
> collection) :( Could any suggest from where come other Cs? Thanks in advance
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to a topic in the Google 
Groups "sqlalchemy" group.
To unsubscribe from this topic, visit 
https://groups.google.com/d/topic/sqlalchemy/Kpzqn81Kbcc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to 
sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to