I think I jumped the gun a bit this morning with my excitement. The results are wrong in that they return all of the identifiers in my names table.
species_sentences_secondary = sentences_table.join(entities_table, and_(sentences_table.c.sentence_id == entities_table.c.sentence_id, entities_table.c.deleted == 0 )) print dir(species_sentences_secondary), species_sentences_secondary.c mapper(Zone, zones_table, properties={ "species":relation(Taxa, primaryjoin=zones_table.c.zone_id == species_sentences_secondary.c.sentences_zone_id, secondary=entities_species_normalised_table, viewonly=True ) is my mapper ...... ( I m sorry the naming has changed but I've been updating my code from toy code to real app code) a Zone has many sentences a Sentence has many entities (some of these entities are normalised and has one row in entities_species_normalised, which links to one Taxa) I want to get a list of species mentioned in that Zone...........but I just can't get it right............I have tried everything I can think of, but I just can't see the final step to finish it off. Many thanks in advance Nathan 2009/5/20 Nathan Harmston <iwanttobeabad...@googlemail.com>: > The problem was solved by using a join query and then specifying both > foreign keys and the secondary argument to the relation. > > Many thanks, > > Nathan > > > secondary = sentences_table.join(tag_table.join(processed_tags_table, > processed_tags_table.c.tag_id == tag_table.c.tag_id), > sentences_table.c.sentence_id == > tag_table.c.sentence_id) > > mapper(Zone, zones_table, properties={ > "species":relation(Name, > > primaryjoin=zones_table.c.zone_id == secondary.c.sentences_zone_id, > > foreign_keys = [ secondary.c.sentences_zone_id, names_table.c.name_id > ], > > secondary=processed_tags_normalised_table, > viewonly=True) > > > 2009/5/19 Michael Bayer <mike...@zzzcomputing.com>: >> >> >> On May 18, 2009, at 8:06 PM, Michael Bayer wrote: >> >>> >>> if you want to make a chained join like that, use just primaryjoin(), >>> dont use "secondary", and set viewonly=True. >> >> I might be off on the "dont use secondary" advice. if you do use >> "secondary", "secondary" is the "middle" table, so in this case it >> seems like it would be "tags_table" and the target would be >> "processed_tag_table". >> >>> As an alternative to the above approach, you can also try using >>> traditional relations between each class and use the association proxy >>> to simplify access from one end to the other. >> >> this advice stlll holds though (as does use viewonly=True). >> >> >> >> >> > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---