B newB = makeNewB();
array.addObject(newB);
a.addObjectToBothSidesOfRelationship( b, "bs" );
a.editingContext().processRecentChanges(); // Just in case, but
doesn't appear to help
PrintALotOFStuffHere;
try {
saveChanges();
} catch OL exception {
for all objects obj in array {
obj.removeObjectFromBothSidesOfRelationship( a, "a" );
Have you tried
a.removeObjectFromBothSidesOfRelationship( obj, "bs" );
obj.editingContext().deleteObject(obj);
Have you made other changes in the EC? If not, ec.revert() should
handle all this much more cleanly.
}
array.removeAllObjects();
// Do some refaults
}
}
In "print a lot of stuff", I do print, between other stuff:
- The Bs in the a.bs() relationship.
- The EC deleted, inserted and updated objects.
Well, when there's no OL failure, this works.
When there's a OL failure, on the second try, I get the following:
The "newB" object created on the first cicle run is NOT on the bs
() relationship, neither in inserted, deleted or updated objects of
the EC. It makes sense: I created and destroyed it before being
able to put it on the data storage.
But... it's precisely that object that causes my error. When I
try to saveChanges in the second run, I get an exception saying the
object is not registered on any EC. Also, all it's relationships
are "null", so I did not forget to remove it from any relationship.
Does something else have a relation to the B entity?
So... if my object belongs to no EC, and if it's not related to
any other object... why the heck is it causing problems? It
shoudn't even exist at that point. How can I ask WO why is it
caring about that object when saving?
The only other thing that comes to mind is the ec.undoManager().
Perhaps this is getting called at somepoint and undoing your deletion
of the new B objects. ec.revert()...