Re: Declaring and using a nested EditingContext

[email protected] Sun, 09 Jul 2006 14:38:08 +0200
Newsgroups gmane.comp.python.modeling
Message-ID <[email protected]>
Please ignore the previous reply, it was only partly completed; I had a =

little keyboard shortcut accident :-)

Hi S=E9bastien,

The test you mention run fine here, but still I get no changes in the =

child in the following example, maybe I am doing something weird here. =

Thanks a lot for looking into this :-)

Cheers,
Paul


EXAMPLE
=3D=3D=3D=3D=3D=3D=3D

pymodel_parentchild.py
----------------------------------------------------------------------------
from Modeling.PyModel import *

Association.defaults['delete'] =3D ['nullify', 'nullify']
Entity.defaults['properties'] =3D []

model =3D Model('parentchild', version=3D'0.1')
model.associations =3D []
model.entities =3D [

         Entity('Person',
                 properties =3D [
                         APrimaryKey('uid',
				isClassProperty=3D0,
				isRequired=3D1, doc=3D'PK'),
                         AString('first_name', width=3D60),
                         AString('last_name', width=3D60),
                 ],
         ),

]
----------------------------------------------------------------------------


Person.py
----------------------------------------------------------------------------
from Modeling import dynamic
__metaclass__ =3D dynamic.CustomObjectMeta

class Person:
         entityName =3D 'Person'
         mdl_define_properties =3D 1
----------------------------------------------------------------------------



test_parentchild.py
----------------------------------------------------------------------------
from parentchild.Person import Person
from Modeling.EditingContext import EditingContext as EC

parent_ec =3D EC()
child_ec =3D EC(parent_ec)

def populate(ec):
         ec.insert(Person(first_name=3D'Anna', last_name=3D'Anderson'))

def result():
         global parent_ec, child_ec

         print "PARENT:",
         for p in parent_ec.fetch('Person'): print p.first_name, =

p.last_name,
         print
         print "CHILD :",
         for p in child_ec.fetch('Person'): print p.first_name, p.last_name,
         print
         print

print "POPULATING AND SAVING CHANGES"
populate(parent_ec)
#parent_ec.processRecentChanges()
parent_ec.saveChanges()

result()

print "CHANGING 'Anna' --> 'anna' in parent AND SAVING CHANGES"
anna =3D parent_ec.fetch('Person', 'first_name=3D=3D"Anna"')[0]
anna.first_name =3D 'anna'
#parent_ec.processRecentChanges()
parent_ec.saveChanges()

result()
----------------------------------------------------------------------------


OUTPUT FROM TEST
------------------------------------------------------------
POPULATING AND SAVING CHANGES
PARENT: Anna Anderson
CHILD : Anna Anderson

CHANGING 'Anna' --> 'anna' in parent AND SAVING CHANGES
PARENT: anna Anderson
CHILD : Anna Anderson
------------------------------------------------------------




S=E9bastien Bigaret wrote:
>    Hi Paul & all,
> =

> [email protected] wrote:
> [...]
>> However, I can't quite get what is meant by the sentence:
>>
>>   - the states of the objects in the result set will reflect any changes =

>> made to them in the parent object store, even the uncommitted ones.
>>
>>  From testing, when I change an object held by the parent EC, and then =

>> do a fetch on that object in the child, the change is not shown in the =

>> object held by the child EC.
> =

> Your understanding is correct, and the changes should appear in the child=
 context. If they are not, it is definitely a bug.
> =

> Could you please send me your example, where the bug appear?  This is som=
ething I did not observe from now on, and I'll be glad to examine and fix i=
t.
> =

>     Cheers,
> =

> -- S=E9bastien.
> =

> =

> PS: Oh, BTW, this is tested in tests/test_EditingContext_ParentChildpy, m=
ethod test_03_fetchedAndModifiedObjectsInParent()
> =

> [email protected] a =E9crit :
>> Hi all,
>>
>> I am reading chapter "5.2 Declaring and using a nested EditingContext" =

>> in the user guide on the web:
>>
>> http://modeling.sourceforge.net/UserGuide/nested-ec-usage.html
>>
>> I understand and can verify by testing (I am using modeling release 0.9) =

>> that:
>>
>> 1. Inserting an object in the parent EC will show up in a fetch in the =

>> child EC.
>>
>> 2. Deleting an object in the parent EC deletes it from the result set in =

>> the child EC.
>>
>> However, I can't quite get what is meant by the sentence:
>>
>>   - the states of the objects in the result set will reflect any changes =

>> made to them in the parent object store, even the uncommitted ones.
>>
>>  From testing, when I change an object held by the parent EC, and then =

>> do a fetch on that object in the child, the change is not shown in the =

>> object held by the child EC.
>>
>> Can anyone get me on the right track here?
>>
>> And last, but not least, thanks for all the work on this magnificent =

>> framework :-)
>>
>> Cheers
>> Paul
>>
>> 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 e=
asier
>> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geroni=
mo
>> http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D120709&bid=3D263057&dat=
=3D121642
>> _______________________________________________
>> Modeling-users mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/modeling-users
>>
>>
> =



-------------------------------------------------------------------------
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 easi=
er
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D120709&bid=3D263057&dat=3D1=
21642