8 messages in com.googlegroups.sqlalchemy[sqlalchemy] Re: association object t...
FromSent OnAttachments
Lele Gaifax19 Dec 2007 01:19.py
Michael Bayer19 Dec 2007 07:20 
Lele Gaifax19 Dec 2007 16:08 
Brett19 Dec 2007 16:41.py
Roger Demetrescu19 Dec 2007 17:00 
Lele Gaifax19 Dec 2007 18:02 
Michael Bayer19 Dec 2007 18:42 
Michael Bayer19 Dec 2007 19:02 
Subject:[sqlalchemy] Re: association object to associate table to itself
From:Michael Bayer (mike@zzzcomputing.com)
Date:12/19/2007 07:02:40 PM
List:com.googlegroups.sqlalchemy

two tricks here - set up SpeciesSynonym as:

class SpeciesSynonym(object): def __init__(self, species): self.synonym = species

that it wasnt raising an exception for no constructor is a bug - ticket #908 added.

The other thing that helps here is to set up your bidirectional relation using a backref, so that the opposite side is set automatically:

mapper(Species, species_table, properties = \ {'_synonyms': relation(SpeciesSynonym,

primaryjoin=species_table.c.id==species_synonym_table.c.species_id, cascade='all, delete-orphan', uselist=True, backref="species" )})

mapper(SpeciesSynonym, species_synonym_table, properties = \ { 'synonym': relation(Species, uselist=False,

primaryjoin=species_synonym_table.c.synonym_id==species_table.c.id), })