On Sep 27, 2012, at 1:55 PM, Ladislav Lenart wrote:

> Hello again.
> 
> I have the following test query:
> 
>    def test_slot_access_after_query(self):
>        q = self.session.query(Foo, Bar).with_labels()
>        q = q.filter(Foo.bar_id == Bar.id)
>        rows = q.all()
>        assert len(rows) > 0
>        with self.assert_no_sql_while():
>            for (each_foo, _each_bar) in rows:
>                each.bar.data # <-- FAILS HERE
> 
> SQLAlchemy emits SQL to fetch each.bar's data. I do not understand why. I
> expected that:
> * Bar is already cached in the session.
> * each.bar first checks if a bar with the appropriate id is present in the
> session and if so, return it.
> 
> What am I doing wrong?

not sure, is "each.bar" a typo and you meant "_each_bar" ?    or are you trying 
to fetch a relationship along Foo-> Bar ?  if its a relationship and the 
linkage is not a simple many-to-one, then it emits SQL.


-- 
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