Re: [Modeling-users] Insert inverse relationship reference problem
Status: Abandoned
Brought to you by:
sbigaret
From: Sebastien B. <sbi...@us...> - 2005-03-05 17:20:02
|
Hi, Sorry for the late answer. Wara Songkran <war...@gm...> wrote: > Hi >=20 > I've try to test insertion Ojbect with refference to the others [...] > ec.setAutoInsertion(True) > s =3D Staff() > t =3D Task() > s.addToTasks(t) > ec.insert(s) > ec.saveChanges() >=20 > the staff foreign key in task row is Null. but if I execute > t.setStaff(s). It's work normally. >=20 >=20 > do I have to call t.setStaff(s) explicitly In short: yes, you do. As a general rule, you are responsible for keeping your object graph consistent. Now a bit longer: ec's autoInsertion feature only takes care of calling ec.insert() on the objects that are: - not inserted in the ec yet, - and which are in relation to objects that are already under the control of an EC However, the ec does not play with your relations , it always assumes that the object graph is as the developper wants it to be. If the association is bidirectional, you have to set both relations. Now you can also delegate the work to addObjectToBothSidesOfRelationshipWithKey(), see http://modeling.sf.net/UserGuide/customobject-relationshipmanipulation.html In your case, you'll write:=20 s.addObjectToBothSidesOfRelationshipWithKey(t, 'tasks') or t.addObjectToBothSidesOfRelationshipWithKey(s,, 'staff') -- S=E9bastien. Wara Songkran <war...@gm...> wrote: > Hi >=20 > I've try to test insertion Ojbect with refference to the others >=20 > My Entities are=20 >=20 > Entity('Staff', > properties=3D[ APrimaryKey('id', isClassProperty=3D0, isRequired= =3D1), > AString('firstName', isRequired=3D1, > columnName=3D'firstName'), > AString('lastName', isRequired=3D1, columnName=3D'l= astName'), > ], > ), > Entity('Task', > properties=3D[ APrimaryKey('id', isClassProperty=3D0, isRequire= d=3D1), > ADateTime('startTime', columnName=3D'startTime', > externalType=3D'datetime'), > ADateTime('completeTime', > columnName=3D'completeTime', externalType=3D'datetime'), > AString('isCompleted',doc=3D'yes or no') > ], > ), >=20 > and my association is >=20 > Association('Task', 'Staff',=20 > relations=3D['staff', 'tasks']), >=20 > and when i execute >=20 > ec.setAutoInsertion(True) > s =3D Staff() > t =3D Task() > s.addToTasks(t) > ec.insert(s) > ec.saveChanges() >=20 > the staff foreign key in task row is Null. but if I execute > t.setStaff(s). It's work normally. >=20 >=20 > do I have to call t.setStaff(s) explicitly >=20 > Regards > Wara Songkran |