yeah...the hack youre doing, while I havent looked into it deeply, I can tell is going to be very tricky to make that work. at the very least you want to be on the latest SVN since I committed some major fixes to inheritance this weekend.

what I dont understand is, at what point do you want to query the "organizations" table and when the "persons" table ? if you have just one mapper querying "both", its going to join base, organizations, and persons every time, but each row will only have one or the other. similarly each of your object instances will have attributes of both classes, just being empty on one side or the other. seems a little wasteful.

it seems to me it would be "easier" to just map against the actual SELECT statement that joins all three tables, and not use mapper inheritance for this. youd have one Mapper that knows about the Base class. then your MapperExtension would override create_instance to provide Organization or Person objects....thats the single point at which objects are instantiated. that way the mapper would just deal with Base objects and not even know about the subclasses.

*or*, maybe you could expermiment with having two separate mappers for Organization and Person, and just load them using "dual mappers", as illustrated in http://www.sqlalchemy.org/docs/ adv_datamapping.myt#adv_datamapping_resultset . this might be a lot easier, you just might need to create some get/select logic on top to produce your queries.

ill let you know if i come up for any other tricks in this department.


On Feb 28, 2006, at 12:10 AM, Marko Mikulicic wrote:

Hello,

I would like to have some classes derive from a common ancestor and access them all together having the mapper select the right class for each instance. I've done a little hack using MapperExtension and outerjoins, however there are some problems with this solution.
See the attached files.

<polymorphic.py>
<polytest.py>

One problem is that patching the __class__ attribute with the append_result hook the identity of the instances is not the same as those that come from their primary mapper.

Is there some better way to do that?

If I do a objectstore.commit() after modifying objects patched that way then I can see the changes also from the primary mappers. Is that safe or there are some subtle interactions that could cause problems?

--
marko



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to