On Dec 28, 2008, at 10:54 AM, Alan Shields wrote:

>
> Let me check my understanding of what you're suggesting. The result
> would look something like:
>
> crates2apples = select([ crate_table.c.id,
>                                       apple_table.c.id,
>                                       apple_table.c.description,
>                                       apple_table.c.stem_length ],
>                                      from_obj = <join here>)
> crates2apples_mapper = mapper(Apples, crates2apples, non_primary=True)
>
> mapper(Crates, crate_table, properties={
> 'apples': relation(Apples, <actually, I have no clue what would go  
> here>),
> })
>
> And, just to be clear, I could eagerload the Crates.apples relation
> under this configuration?


you'd put  
"primaryjoin=crate_table.c.crate_id==crates2apples.c.some_column"  
inside of the relation().    This approach usually makes the  
eagerload's job easier, as far as constructing a join from crate_table  
to Apple.

Of course the only way to know the best approach is to know exactly  
what data you need to be loading.    Its often the case that the best  
approach overall is to use just a plain Crate->Apple relation with  
nothing special, then just use a simple in-python property to give you  
a particular "view" of that collection.   If you're dealing with small  
numbers of records that's how I'd usually do something like this.  I  
think the docs try to make a similar point on this.



--~--~---------~--~----~------------~-------~--~----~
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