Thanks for the link. It seems I missed that.

On Mon, Aug 29, 2016 at 4:45 PM Mike Bayer <mike...@zzzcomputing.com> wrote:

>
>
> On 08/29/2016 08:32 AM, mgozda...@starfishstorage.com wrote:
> > 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?
>
> joinedload() only refers to collections that are fully loaded on User
> and aren't part of what you can manipulate in the query.  Take a look at
>
> http://docs.sqlalchemy.org/en/latest/orm/loading_relationships.html#the-zen-of-eager-loading
> .
>
>
>
>
>
> >
> > --
> > 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
> > <mailto:sqlalchemy+unsubscr...@googlegroups.com>.
> > To post to this group, send email to sqlalchemy@googlegroups.com
> > <mailto:sqlalchemy@googlegroups.com>.
> > Visit this group at https://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/ACO-Jhdud3w/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 https://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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to