You create a nested EditingContext by simply supplying the parent EditingContext to the initializer:
>>> from Modeling.EditingContext import EditingContext >>> parent_ec=EditingContext() >>> child_ec=EditingContext(parent_ec)
You fetch objects exactly the same way you do with a standard EditingContext, as described in section 4.5, ''Fetching objects''.
However, the result set you'll get will probably be different than the one you would get by asking a standard EditingContext, because:
All currently supported operations on an EditingContext, such as inserting or deleting an object, making changes and validating them, are available in a child EditingContext without any modifications to your code.
You save the changes made in a child EditingContext to its parent just by calling saveChanges() on it. Remember: a nested EditingContext saves its changes to its parent, NOT to the database. If you want to make them persistent, you will need the two following steps:
>>> child_ec.saveChanges() # save changes to the parent_ec >>> parent_ec.saveChanges() # save the changes to the database
Discarding the changes made in a child EditingContext is as simple as forgetting the child (e.g. dy deleting it). Remember that a parent EditingContext will never see the changes made in its children until saveChanges() is explicitly called on them.
Is it possible to declare a child of an already nested EditingContext? Yes! Every EditingContext can have children, irrespective of whether it is already nested; the depth of a hierarchy defined by parent/children EditingContext is indeed unlimited.
Comments are welcome: Sebastien Bigaret / Modeling Home Page