Aaron Spike wrote: > I've got a one-to-one relationship something like this. > > class Person(object): > pass > class Photo(object): > pass > > persons_table = Table('persons', metadata, > Column('id', Integer, primary_key=True), > Column('firstname', String(255), > Column('lastname', String(255), > ... > ) > photos_table = Table('photos', metadata, > Column('person_id', Integer, primary_key=True), > Column('photo',), > ForeignKeyConstraint(['person_id'], > ['persons.id'],'persons_photos_fk') > ) > > photomapper = mapper(Photo, photos_table) > personmapper = mapper(Person, persons_table, > properties={'photo':relation(Photo, uselist=False)}) > > And now to access a person's photo I have to do "person.photo.photo". Is > there anyway I can do "person.photo" instead and still have it lazy load > the photo? I could make a getPhoto() method on the class but is a > property possible?
I read through the advanced mapper stuff in the docs a few more times and I think I've got a start in the right direction. Just want to make sure I'm not missing something or misunderstanding the concequences. persons_join = join(persons_table, photos_table, persons_table.c.id==photos_table.c.person_id) personmapper = mapper(Person,persons_join, properties={'photo':deferred(photos_table.c.photo), 'id':[persons_table.c.id,photos_table.c.person_id]}) This seems to work just fine. Is there anything else I need to do? Anything I should watch out for? Aaron Spike ------------------------------------------------------------------------- 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