Re: [Modeling-users] EditingContext and Zope Sessions
Status: Abandoned
Brought to you by:
sbigaret
From: Sebastien B. <sbi...@us...> - 2003-09-10 20:36:22
|
Hi, frobni barka <fro...@ya...> wrote: > I have another question concerning the sample code at > the main page. >=20 > john.addToAddresses(a_john); a_john.setPerson(john) >=20 > Wouldn't it be enough to just use one of the above > statements, because they do the same thing? No, it would not be enough, let's see why. As a general rule, the graph of objects hold by an EditingContext should be kept consistent. As the association is bi-directional in the PyModel exposed on the first page, both objects should be modified with the relevant informations. This has nothing to do with RDBMS: imagine you just write: >>> address_john.setPerson(john) This does not update 'john' itself, and its list of addresses will not contain the new addresses, that's why you also need to update the other side. They do not really /do/ the same thing, but they both participate in updating the association. In fact, that has little to do with the framework, except that the framework expects the graph of objects to be consistent --or it could make wrong decisions, in this case, it might incorrectly analyse the changes that have been made and as a consequence, not save the modifications as expected. Now, every object in the framework inherits from CustomObject which has a mix-in named 'RelationshipManipulation' that can ease the way you update the relationships. It uses the model to determine what should be done when you modify a relationship; for example, >>> john.addObjectToBothSidesOfRelationshipWithKey(a_john, 'addresses') will update john and a_john in the same time. Moreover, imagine a_john was previously bound to john2, it will also remove a_john from john2's list of address. This is a convenient method, I think, that can be of some help. For further details about this, please see section 8.1 in the User's Guide: http://modeling.sf.net/UserGuide/customobject-relationshipmanipulation.html Regards, -- S=E9bastien. |