I received reports of identical Core Data validation errors from two users in 
the last week, which I cannot reproduce.  It involves these relationships, 
which are inverses of one another:

    Bar         Foo
    foo <<----> bars 

In both directions, the Delete Rule is "Nullify", and for the to-many relation, 
Min Count and Max Count are "none".  Bar's 'foo' is optional.  Foo's bars are 
not optional, although that does not seems to be the problem since all of the 
errant Foo objects in the reports seem to have bars.

The reports indicate (rather strangely, but I'm watching my word count here) 
that the problem is "Dangling reference to an invalid object".  Searching list 
archives tells me that this has been due to setting a relationship in 
-awakeFromFetch, which is illegal.  But I checked my project carefully and I'm 
not doing that.

However, in the error reports, I see that only one of the foo:bar relationships 
of the Foo objects tagged as NSValidationErrorObject are fulfilled:  The Foo's 
'bar' contains several Bar objects, but these Bar objects' 'foo' is nil.  I 
think that's the cause of the validation error – Core Data expects pairs of 
inverse relationships with Delete Rules both set to Nullify to always be either 
point to one another or both be nil.

Indeed, I cannot reproduce this 1/2 relationship in debugging…

• First, I try to do it by only creating one half.  When my app creates a Foo, 
it adds a couple of Bar objects immediately.  When I do that in debugging, Core 
Data immediately fulfills the inverse, so that the Bar objects now have a foo.  
So I have a two relationships.

• Then, I try to do it by deleting one half.  I grab a Bar which has a 'foo', 
and set send it setFoo:nil.  Core Data immediately removes this Bar object from 
the 'bars' set of its former Foo object.  So I have no relationships.

Summarizing, the paradox is that there I cannot, in code, create a 1/2 
relationship, apparently because of the data model settings.  But it happens 
occasionally in the wild.  How?

Thanks,

Jerry Krinock

_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to