With the methods defined by the interface RelationshipManipulation (implemented by CustomObject), you can assign an object Book to another object Author, and conversely, without even knowing if the relationship has some inverse relationship, or even if the relationship is toOne or toMany: all that you need to know is the 'key' (i.e. the name of the relationship) to which you want to add an given object. Example:
Here, the framework analyses the underlying model, does what is necessary
so that your objects are in sync. Moreover, suppose
has author2 assigned to relationship author, then the inverse
relationship joining author2 to aBook is nullified, so that
the graph of object remains consistent.
Compare this with that you normally do by hand, the explicit way:
_author=aBook.getAuthor() if _author: _author.removeFromBooks(aBook) aBook.setAuthor(anAuthor) anAuthor.addToBooks(aBook)
addObjectToBothSidesOfRelationshipWithKey does exactly the same thing, taking care of all the details for you (even it's a bit slower than the explicit statements because it has to examine the model).
This can come in handy for rapid prototyping, or to make things smoother when you are beginning the dev. and that the model can rapidly change, or for designing generic algorithms where the manipulated objects and relationships are not known at runtime.
Last note: the inverse method is the following one:
and works on the same principles.
Comments are welcome: Sebastien Bigaret / Modeling Home Page