On Apr 1, 2011, at 1:12 AM, Inside Zhou wrote:

> Thank you for you answer,but I'm sorry,I don't quite follow you.
> 
> My confusion is that with the "s.query(User).all()",SA issues SQL stmt the 
> same as "user_table.select().execute()",but why the latter stmt can return 
> the row what I expected whereas the former couldn't?
> 
> besides,the table in DB change nothing after reflection,just like original 
> one(no PK there) :
> 
> user_table = Table('user', metadata,
>     Column('id', Integer),
>     Column('name', Unicode)
> )

NULL is not a valid value for a primary key and in fact the ORM sees NULL 
inside of primary key columns all the time when loading rows representing an 
OUTER JOIN.    Query asks the User mapper to construct new objects + identities 
for each row it receives, but the mapper skips those rows that have NULL for a 
primary key.     This is an ordinary occurrence when "joined eager loading" is 
used to OUTER JOIN to a related table.

If OTOH you issued s.query(User.id, User).all(), you'd get a tuple back like 
(None, None) for the row in question.   When you query for individual columns 
the Query returns those as is without consulting the mapper.


> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> 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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to