On Nov 15, 2010, at 3:53 PM, ahamilton wrote:

> I have a standard 1 to Many relationship between two model classes
> (declarative base).  In this project I have an Object class that will
> have many instances of the Property class.  I added the lazy=False
> option to the relationship declaration to force eager loading of
> Property instances when I query for an Object instance.  Now, when I
> run session.query(model.Object).get(id), SA executes 1 SELECT...JOIN
> statement for all columns in both tables.  I would expect SA to do
> this.  However, it also executes N SELECT statements for the Property
> class, where N equals the number of Property instances linked to the
> Object instance.  Am I crazy, or should SA only be executing 1
> SELECT...JOIN statement and filling in the relationship with the
> result?

this is not nearly enough detail to know the answer, what SELECT statements are 
being emitted, what table is the target, how are the mappings configured, at 
what point is the SELECT emitted, etc.

It sort of seems like you might be saying that object.properties loads, but 
then it loads property.object for each one (though you didn't use the word 
'backref', no mappings here, etc.).  That can be caused by many things, 
including a mis-configured many-to-one, or the parent Object falling out of 
scope before Property.object is accessed, etc.



> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to sqlalch...@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.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@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