Aaron Spike wrote:
>> 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?
from my recent work with Hibernate ive learned that hibernate does in fact
have the ability to create a relationship to another table, where you get
just a scalar reference back, such as a string, number or a date. I think
it might be worthwhile for SA to have an enhancement that supports this
pattern. it would probably create a mapped class behind the scenes that
is somehow proxied so that you just deal with the scalar attribute you
want (bu t this implies that someone might want to get at that hidden
mapped object too...).
> 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()
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....
-------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users