if you assign a mapper to Base and a separate mapper to Person youre going to have problems, since each class is associated with a mapper via an attribute "_mapper" attached to the class, and you effectively have two different mappers dealing with Person objects and its going to get ugly. you might want to try insuring that the "_mapper" attribute attached to Person is the same as that attached to Base.

I still think separate mappers and using the method described in "Result Set Mapping" might be less error prone. but try seeing how well you do if you maintain control of the "_mapper" attribute (its also described in http://www.sqlalchemy.org/docs/ adv_datamapping.myt#adv_datamapping_class ).


On Feb 28, 2006, at 3:02 PM, Marko Mikulicic wrote:


On 28.02.2006., at 20:10, Michael Bayer wrote:

Ah nice.
When I select objects from Person.select() I get the same instance. Is possible to obtain this behaviour using custom object creation?


show me more specifically what you mean.

from the previous attachments (augmented with prints):

print "---------------"
print "Using pm mapper"
print "---------------"

print pm.select()

for o in pm.select():
    o.doSomething()

print pm.select()

# commit necessary to see changes because modifications are not tracked with the "pm" mapper
print "committing"
objectstore.commit()

print pm.select()

print "-------------------"
print "Using Person.mapper"
print "-------------------"

# Works without commit because the mapper returns the same instances
for o in Person.select():
    o.doSomething()
print Person.select()

**************
outputs:
**************

[]
---------------
Using pm mapper
---------------
[<Organization 18388048: Label Bleu, David Krakauer>, <Person 18389968: Smith, John>, <Base: 18362224: base>]
organization adding x to contact
person adding y to address
base doing nothing
[<Organization 18362192: Label Bleu, David Krakauer>, <Person 18390608: Smith, John>, <Base: 18362224: base>]
committing
[<Organization 18389392: Label Bleu, David Krakauerx>, <Person 18389008: Smith, Johny>, <Base: 18362224: base>]
-------------------
Using Person.mapper
-------------------
person adding y to address
[<Person 18389008: Smith, Johnyy>]

-----------

in the first example every select from the pm mapper yeilds different objects (different python id()).
In this case the modifications are not visible until the commit.

in the second example the modification of the objects are directly visible in the same thread because Person.select() returns the same objects.

I was wondering if it was possible to have the same behaviour using MapperExtension create_instance.

--
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



-------------------------------------------------------
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