On 8/21/06, Michael Kent <[EMAIL PROTECTED]> wrote: > I'm having trouble figuring out how to access the data on the 'one' side of a > 'many-to-one' relationship. > > If I have the following setup: > > personTable = Table('person', > Column('person_id', Integer), > Column('name', String(20)), > Column('address', ForeignKey('address.address_id'), > ) > > addressTable = Table('address', > Column('address_id', Integer), > Column('street', String(20), > ) > > class Person(object): > pass > > class Address(object): > pass > > personMapper = mapper(Person, personTable) > > addressMapper = mapper(Address, addressTable, > properties=dict(persons=relation(Person))) > [snip] > > Why is it easy to go in one direction, but not in the other. What am I > missing? > > Thanks.
You want to use a backref for that: http://www.sqlalchemy.org/docs/datamapping.myt#datamapping_relations_backreferences Note that the documentation example is the reverse of yours: you have multiple People sharing one Address, while the example in the docs is of one User with multiple Addresses. It should be pretty easy to figure out, nonetheless. -- Robin Munn [EMAIL PROTECTED] GPG key 0xD6497014 ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Sqlalchemy-users mailing list Sqlalchemy-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users