On Sun, Dec 28, 2008 at 9:29 AM, Michael Bayer <mike...@zzzcomputing.com> wrote: > 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.
Several thousand records, sadly. I will probably be able to get away with the in-python property for most cases, but this is the ugly one. So, I gave that a shot and I must have messed up somewhere. crates2apples = \ select([ crate_table.c.id.label("crate_id"), apple_table, ], from_obj = crate_table.\ <bunch of joins>.outerjoin(apple_table, <condition>)) crates2apples_a = crates2apples.alias('_crates2apples') mapper(Apple, crates2apples_a, non_primary=True) mapper(Crate, crate_table, properties={ 'apples': relation(Apple, lazy=True, uselist=True, viewonly=True, primaryjoin= crate_table.c.id == crates2apples_a.c.crate_id, ), }) is the basic setup. I'm using the alias because there was a warning about needing to make an alias otherwise. Under this setup, I get the following error: ArgumentError: Could not determine relation direction for primaryjoin condition 'crate_table.id = _crates2apples.pool_id', on relation Crate.apples (Apple). Specify the foreign_keys argument to indicate which columns on the relation are foreign. If I specify foreign_keys = [ crates2apples_a.c.crate_id, ], I get... ArgumentError: Can't determine relation direction for relationship 'Crate.apples (Apple)' - foreign key columns are present in neither the parent nor the child's mapped tables. If I specify foreign_keys = [ crate_table.c.id ], I get... ArgumentError: Remote column '_crates2apples.crate_id' is not part of mapping Mapper|Crate|crate_table. Specify remote_side argument to indicate which column lazy join condition should bind. Which is about what I'd expect. I'm sure I'm going wrong somewhere. Enlightenment would help. :-) Thanks a bunch for taking the time, 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 -~----------~----~----~----~------~----~------~--~---