On Aug 6, 2013, at 6:23 PM, Jonathan Vanasco <jonat...@findmeon.com> wrote:
> I have three tables that are structured somewhat like this: > > Document > * id > * all_images = sa.orm.relationship(Document2Image) > > Image > * id > * all_documents = sa.orm.relationship(Document2Image) > > Document2Image > * id > * document_id > * image_id > * image_type_id > * document = sa.orm.relationship(Document) > * image = sa.orm.relationship(Image) > > > > is there a convenient way to set up a relationship on Document where it maps > to Document2Image with a specific Document2Image.image_type_id ? > > I believe I want a variant of the Association Proxy [ > http://docs.sqlalchemy.org/en/rel_0_8/orm/extensions/associationproxy.html ] > that was listed in Relationships - Association Object [ > http://docs.sqlalchemy.org/en/rel_0_8/orm/relationships.html#association-object > ] you can build a relationship from Document to Document2Image using a custom primaryjoin, then relationship to Image, then association proxy. Or, you can produce a select() of what rows you want from Document2Image, then make that as the "secondary" argument between a single relationship on Document->Image. If OTOH you want a join condition that uses columns from Document2Image and Image at the same time, sometimes you can make a select() of those two things, then create a non primary mapper to Image using that select() as the base, then Document gets a relationship referring to that non-primary mapper.
signature.asc
Description: Message signed with OpenPGP using GPGMail