[sqlalchemy] joinedloads under a subqueryload

2014-10-21 Thread Jonathan Vanasco
I've been staring at this for a while, and can't figure out a way to make 
the mapper happy:

i have 3 Classes (tables):

* List (list)
* ListItem (list_item)
* ItemType1 (item_type_1)
* ItemType2 (item_type_2)
* ItemType3 (item_type_3)

until now i've been using a joinedload

   query = s.query(List)\
.options(
joinedload('list_item'),
joinedload('list_item.item_type_1'),
joinedload('list_item.item_type_2'),
joinedload('list_item.item_type_3'),
)

The performance is starting to become less than optimal, so I wanted to try 
creating a subquery for 'list_items', which has the `item_type_1`/2/3 
connected to it as a joinedload

the closest I can get is this:

   query = s.query(List)\
.options(
subqueryload('list_item')\
   .joinedload('item_type_1')
   )

at that point, the unbound subquery can only join things from 
`item_type_1`.  i can't figure out how to join other relationships of 
`list_item`

is it possible to joinedload mutliple trees/paths onto a subqueryload ?

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


Re: [sqlalchemy] joinedloads under a subqueryload

2014-10-21 Thread Michael Bayer

 On Oct 21, 2014, at 6:07 PM, Jonathan Vanasco jvana...@gmail.com wrote:
 
 I've been staring at this for a while, and can't figure out a way to make the 
 mapper happy:
 
 i have 3 Classes (tables):
 
 * List (list)
 * ListItem (list_item)
 * ItemType1 (item_type_1)
 * ItemType2 (item_type_2)
 * ItemType3 (item_type_3)
 
 until now i've been using a joinedload
 
query = s.query(List)\
   .options(
   joinedload('list_item'),
   joinedload('list_item.item_type_1'),
   joinedload('list_item.item_type_2'),
   joinedload('list_item.item_type_3'),
   )
 
 The performance is starting to become less than optimal, so I wanted to try 
 creating a subquery for 'list_items', which has the `item_type_1`/2/3 
 connected to it as a joinedload
 
 the closest I can get is this:
 
query = s.query(List)\
   .options(
   subqueryload('list_item')\
   .joinedload('item_type_1')
   )
 
 at that point, the unbound subquery can only join things from `item_type_1`.  
 i can't figure out how to join other relationships of `list_item`
 
 is it possible to joinedload mutliple trees/paths onto a subqueryload ?

in the old way, you’d say:

subqueryload(‘list_item’),
joinedload('list_item.item_type_1'),
joinedload('list_item.item_type_2'),
joinedload('list_item.item_type_3'),

that will still work.

new way you can also say:

subqueryload('list_item').joinedload('item_type_1'),
defaultload('list_item').joinedload(item_type_2'),
defaultload('list_item').joinedload('item_type_3'),

or variants thereof.





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


Re: [sqlalchemy] joinedloads under a subqueryload

2014-10-21 Thread Jonathan Vanasco


 subqueryload(‘list_item’),
 joinedload('list_item.item_type_1'),
 joinedload('list_item.item_type_2'),
 joinedload('list_item.item_type_3'),


ah!  so sqlalchemy is smart enough to magically map the joinedloads onto 
the subqueryload! 

I never would have guessed that!

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