What does core data do during a Save As?
What does core data do during a Save As?
- Subject: What does core data do during a Save As?
- From: Gideon King <email@hidden>
- Date: Sat, 2 Oct 2010 02:03:11 +1000
Hi, I'm still trying to sort out what is happening to my to-one relationships during a Save As operation (see Core data: Inverse relationships with subclasses thread for context if necessary, but this really is a standalone thread now) - it turns out that the subclasses/subentities questions were a bit of a red herring and it applies to all to-one relationships with inverse relationships. I have narrowed it down to the following:
1. Prior to saving I manually go through all the registered objects and make sure they pass the validateForInsert and validateForUpdate checks. This confirms that everything is OK before saving.
2. The Save As operation creates a new atomic store, and loads from an empty temporary file.
3. It then does a migration to the new atomic store. I really don't understand this process, but somewhere along the way, it calls awakeFromFetch on all my existing managed objects (even though as far as I can tell, no fetches have been done, and certainly no new atomic store cache nodes have been created).
4. It then validates my managed objects, and this time the insert validation checks fail for all my to-one relationships that have inverse relationships.
Here is a typical failure (they happen on validateForInsert:):
Error Domain=NSCocoaErrorDomain Code=1550 UserInfo=0x11baadf10 "backgroundStyle is not valid."
{
"Dangling reference to an invalid object." = "<null>";
NSAffectedObjectsErrorKey = (
"<NMFillStyleMO: 0x11b75b290> (entity: FillStyle; id: 0x11b7a8090 <x-coredata://7FFCE521-A755-4341-86DE-971B085D77D7/FillStyle/tB496F77D-2950-43FF-93CC-B49FEE7FF269207> ; data: {\n ... theme = \"0x11b7a8f80 <x-coredata://7FFCE521-A755-4341-86DE-971B085D77D7/Theme/tB496F77D-2950-43FF-93CC-B49FEE7FF269226>\";\n ... })"
);
NSLocalizedDescription = "backgroundStyle is not valid.";
NSValidationErrorKey = backgroundStyle;
NSValidationErrorObject = "<NMThemeMO: 0x11b75eb50> (entity: Theme; id: 0x11b7a8f80 <x-coredata://7FFCE521-A755-4341-86DE-971B085D77D7/Theme/tB496F77D-2950-43FF-93CC-B49FEE7FF269226> ; data: {\n ... backgroundStyle = \"0x11b7a8090 <x-coredata://7FFCE521-A755-4341-86DE-971B085D77D7/FillStyle/tB496F77D-2950-43FF-93CC-B49FEE7FF269207>\";\n ... })";
NSValidationErrorValue = "<NMFillStyleMO: 0x11b75b290> (entity: FillStyle; id: 0x11b7a8090 <x-coredata://7FFCE521-A755-4341-86DE-971B085D77D7/FillStyle/tB496F77D-2950-43FF-93CC-B49FEE7FF269207> ; data: {\n ... theme = \"0x11b7a8f80 <x-coredata://7FFCE521-A755-4341-86DE-971B085D77D7/Theme/tB496F77D-2950-43FF-93CC-B49FEE7FF269226>\";\n })";
}
Now seeing as my code has not touched the managed objects since I last validated them, all I can assume is that either:
a) I have something set up incorrectly in my model which is causing the problems (I can't see how, but I guess it's possible)
b) I have not set things up correctly in the cache nodes, and it's trying to populate the managed objects with something invalid (I don't see how this could be the case, seeing as the ordinary loading and saving works fine)
c) I have set up something incorrectly in the managed objects which is causing these relationships to not be established properly upon migration of the store (again, I can't see how), or
d) something I haven't thought of or am not aware of...
When I break on the validation, the objects all exist, they are valid, the relationships exist, and I can use valueForKey to traverse the relationships in both directions. As you can see from the above, the theme object has a reference to the background style which is a fill style, and indeed the fill style exists and the address matches, and the fill style has a "theme" relationship that points back to the theme object.
I can't help thinking that if I understood what is going on behind the scenes during Save As, I might be able to have a chance of working this out.
I'd really appreciate it if someone could give me a clue as to what may be causing this.
Thanks
Gideon
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden