Re: Why is it wrong to have relationships without an inverse in Core Data?
Re: Why is it wrong to have relationships without an inverse in Core Data?
- Subject: Re: Why is it wrong to have relationships without an inverse in Core Data?
- From: Rick Mann <email@hidden>
- Date: Fri, 21 Jun 2013 16:50:32 -0700
On Jun 21, 2013, at 14:10 , Rick Mann <email@hidden> wrote:
>
> On Jun 21, 2013, at 14:03 , Kyle Sluder <email@hidden> wrote:
>
>> On Fri, Jun 21, 2013, at 01:55 PM, Rick Mann wrote:
>>> But Core Data complains that activeChild is misconfigured because it
>>> doesn't have an inverse. But I have no need for an inverse, why does Core
>>> Data?
>>
>> Apple's explanation, straight from the docs:
>> http://developer.apple.com/library/mac/documentation/cocoa/conceptual/coredata/Articles/cdRelationships.html#//apple_ref/doc/uid/TP40001857-SW6
>>
>> --Kyle Sluder
>
> Oh hey, I just realized, I can re-use an existing inverse relationship. Given the example I stated earlier,
>
> Parent
> children to-many to Child (inverse is parent)
> activeChild to-one to Child
>
> Child
> parent to-one to Parent
>
> I can re-use the parent relationship:
>
> Parent
> children to-many to Child (inverse is parent)
> activeChild to-one to Child (inverse is parent)
>
> Child
> parent to-one to Parent
>
> At least, Xcode no longer warns about it being a one-way relationship. This makes me happy, and hopefully makes Core Data happy.
Nope, I'm wrong. While Xcode doesn't complain about this, Core Data ends up nilling out relationships that shouldn't be nil. Moreover, there's no way to specify what should happen to activeChild when that child is deleted, vs specifying what should happen to children when that child is deleted.
You can either add a redundant "parent" relationship, or just accept the warning and manually clean it up in -prepareToDelete.
--
Rick
_______________________________________________
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