Michael Bayer wrote: >> 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]}) > > good thinking. although this will always join against the photos table > which produces a more complicated query and also wont load any person at > all who does not have a photo. not sure if thats a problem here. id > almost rather go with an approach that proxies at the object level, like > the Photo class would have a __call__() method that gives you the "photo" > attribute, for example: > > person = session.query(Person).get(5) > photo = person.photo()
I started out this way, with an accessor, but I wanted to see if there was another way. > this is headed towards the enhancement im thinking of. > >> Anything I should watch out for? > > falling pianos are a good thing to look out for. that and, if theres a > person with no photo, or a person with more than one photo would load two > person rows.... I will be particularly cautious when walking under pianos. Now this is an enforced one-to-one relationship so I will never have two photos. I have already contemplated the no photo people. I was wondering if I would need to use an outer join instead or some sort of join(lazy=True), but I haven't investigated those options yet. In practice I'm uneffected by the join against the photos table, because I am accessing people via a search function that calls a stored proceedure and joins the results with the people table, that set is them mapped to objects. I was a bit surprised that this worked. I expected SA to complain that the fields contained in the photo table weren't in the set (I've seen an error like that before somewhere when mapping) but it didn't. Something still doesn't seem right so I'll keep thinking. I'm mainly trying to avoid doing something that might break later. Thanks for the __call__() suggestion. I like that. 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