Hi

I have a question about the difference between .join() and 
.options(joinedload()).

I'm using example from 
http://docs.sqlalchemy.org/en/rel_1_0/orm/extensions/hybrid.html#working-with-relationships
 
(the one with SavingsAccount and User)
The doc shows SQL for 

Session().query(User, User.balance).join(User.accounts).filter(User.balance 
> 5000)

which is 

SELECT "user".id AS user_id, "user".name AS user_name, account.balance AS 
account_balance
FROM "user" JOIN account ON "user".id = account.user_id
WHERE account.balance > :balance_1

if I change the Python code to

Session().query(User, 
User.balance).options(joinedload(User.accounts)).filter(User.balance > 
5000))

it generates different SQL, which I believe does a cartesian join:

SELECT "user".id AS user_id, "user".name AS user_name, account.balance AS 
account_balance, account_1.id AS account_1_id, account_1.user_id AS 
account_1_user_id, account_1.balance AS account_1_balance 
FROM account, "user" LEFT OUTER JOIN account AS account_1 ON "user".id = 
account_1.user_id 
WHERE account.balance > :balance_1

Is there something I'm missing?

-- 
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to