• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Removing an object from an inverse (not deleting) does not remove from the other side?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Removing an object from an inverse (not deleting) does not remove from the other side?


  • Subject: Re: Removing an object from an inverse (not deleting) does not remove from the other side?
  • From: Andre <email@hidden>
  • Date: Thu, 29 Dec 2005 00:27:19 -0800

Thank you very much for your reply.
Hope this is something simple I am overlooking...

Chris Hanson wrote:

On Dec 28, 2005, at 1:41 PM, email@hidden wrote:

Is the standard behavior of removing an object from a many-to-many with inverse relationship using NSArrayController not to remove the object from the other side of the relationship?

When you remove an object from a relationship in Core Data, the inverse relationship is maintained for you automatically.
When I add, yes, when I remove, no. Not from an NSArrayController bound to a to-many relationship in another controller.
If I set "delete on remove" at the NSArrayController, it removes both sides of the inverse like I expect, but I dont' want to delete, because its a many-to-many inverse, so I would end up nulling all the other objects on the other side.

This is completely orthogonal to whether you use a controller object to manipulate your objects or whether you write code yourself to manipulate them. As long as you're manipulating the relationship correctly, the appropriate behavior should result with respect to both it and its inverse.
Here's the strange thing, if I call something like overriding:

- (void)remove:(id)sender
{
NSSet *mySelectedObjects = [NSSet setWithArray:[self selectedObjects]];

//this next one is selected objects of my content's - NSArrayController
//the modelKey represents the same key used to get my own content from the other NSArrayController
NSArray *targetSelection = [target selectedObjects];
NSEnumerator *targets = [targetSelection objectEnumerator];
id aTarget= nil;

while (aTarget = [targets nextObject])
{
[[aTarget mutableSetValueForKey:modelKey] minusSet: mySelectedObjects ];
}
}

....I get my NSManagedObject subclass (the objects who's to-many relation this controller is using for content to remove and add) to process the methods I defined (KVC compliant) such as removeXXXObject: (XXX *)XXXobject

Like so: (I'm not neccesarily using these names for my classes, but just to illuminate better)

CitizensArrayController CountryArrayController
================== ==================
citizens -------content--from--------> selection.citizens

Adding a citizen to a country adds the country to the citizen like I expect.
Removing a citizen from the CitizensArrayController and its removed from the country, but the inverse (from citizen to country) is not, citizen still thinks its part of a country...

This relation is many-to-many with inverse.

Here are some things to look at:

(1) Is your array controller set to entity mode?
Yes

(2) Does your array controller have the correct entity set?
Yes (I assume an NSManagedObject subclass still does not mean it should be set to class mode)

(3) Does your array controller have its managedObjectContext binding configured and bound to a valid managedObjectContext?
Yes

(4) Are you using a custom managed object class for your entity?
Yes

(5) Does your managed object model specify your custom managed object class for your entity?
Yes

-- Chris


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Follow-Ups:
    • NSTabView backgroud
      • From: email@hidden
References: 
 >Removing an object from an inverse (not deleting) does not remove from the other side? (From: email@hidden)
 >Re: Removing an object from an inverse (not deleting) does not remove from the other side? (From: Chris Hanson <email@hidden>)

  • Prev by Date: Re: [ANN] PSMTabBarControl - Safari-style tabs
  • Next by Date: Re: [ANN] PSMTabBarControl - Safari-style tabs
  • Previous by thread: Re: Removing an object from an inverse (not deleting) does not remove from the other side?
  • Next by thread: NSTabView backgroud
  • Index(es):
    • Date
    • Thread