you probably dont want to bother with "secondary" since it doesnt get  
you anything here and you should likely pare down the size of your  
join condition to something more minimal.    you might want to also  
make life easier and make the relation to a non_primary mapper for  
Apples which maps to a simple select() statement, instead of shoving  
everything into a huge relation().  You don't need to establish  
use_labels as that only has to do with multiple tables in a single  
select() not conflicting on the column namespace.   You also should be  
using 0.5 not only because it handles things like this better but also  
any bugs we fix are likely to be in that series.


On Dec 27, 2008, at 5:24 PM, Alan Shields wrote:

>
> (wow, way to go tab key! Sorry, folks)
>
> I'm having a bit of trouble and I think it may be a deficiency in my
> understanding of SqlAlchemy.
>
> Let's say I have:
>
> Table(Apples)
> Table(Crates)
>
> apples_by_crate = \
>    select([ crate_table.c.id.label("crate_id"),
>                 apple_table.c.id.label("apple_id"),
>             ],
>           from_obj = <long list of tables and conditions here>)
> apples_by_crate_a =  
> apples_by_crate.correlate(None).alias('_apples_by_crate')
>
>
> mapper(Crates,
>              'apples':relation(Apples, viewonly=True,
> secondary=apples_by_crate,
>                                        primaryjoin= apple_table.c.id
> == apples_by_crate_a.c.apple_id,
>                                        secondaryjoin=
> apples_by_crate_a.c.crate_id == crate_table.c.id,
>                                        foreignkeys= [
> apples_by_crate_a.c.apple_id, crate_table.c.id ]))
>
> This works fine...until I try to eagerload apples. Bad Things Happen.
> If it's a confounding factor, know that
> apples_by_crate contains another subquery that also has a column  
> "crate_id".
>
> My impression right now is that I need to .use_labels for my
> subqueries so I don't have conflicting names, but I'm starting to
> wonder if I'm just doing it wrong.
>
> Any advice?
>
> Alan
>
> >


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