Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9125227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:45:19+00:00 2026-06-17T06:45:19+00:00

I have a Core Data database containing (among others) WorkingPlan and Position . A

  • 0

I have a Core Data database containing (among others) WorkingPlan and Position. A WorkingPlan has zero or more Position objects.
Everything works fine, until I am trying to add the same Position to one WorkingPlan multiple times. Instead of having multiple relations (as I would need it to be), i only get one relation. What can I do to get multiple relations to that Position?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:45:20+00:00Added an answer on June 17, 2026 at 6:45 am

    As already mentioned in the comments, a Core Data relationship describes the relations of one object to a set of distinct other objects. It is not possible for one object to have more than one relationship to the same other object.

    One possible solution that comes into my mind is to introduce another entity WorkingStep between WorkingPlan and Position:

    enter image description here

    • steps is a ordered to-many relationship from WorkingPlan to WorkingStep,
    • plan is the inverse to-one relationship,
    • position is a to-one relationship from WorkingStep to Position,
    • steps is the inverse to-many relationship.

    I have suggested an ordered relationship from WorkingPlan to WorkingStep, because I assume that the steps for one plan must be executed in a defined order.

    For example, if the positions “pos1”, “pos2”, “pos1” have to be done for a plan in that order, you would add 3 steps “step1”, “step2”, “step3” to the plan, and both “step1” and “step3” are related to “pos1”, and “step2” is related to “pos2”.

    Adding values to an ordered relationship is a bit tricky. The following code shows how to create the objects described above:

    WorkingPlan *plan1 = [NSEntityDescription insertNewObjectForEntityForName:@"WorkingPlan" inManagedObjectContext:context];
    
    WorkingStep *step1 = [NSEntityDescription insertNewObjectForEntityForName:@"WorkingStep" inManagedObjectContext:context];
    WorkingStep *step2 = [NSEntityDescription insertNewObjectForEntityForName:@"WorkingStep" inManagedObjectContext:context];
    WorkingStep *step3 = [NSEntityDescription insertNewObjectForEntityForName:@"WorkingStep" inManagedObjectContext:context];
    
    Position *pos1 = [NSEntityDescription insertNewObjectForEntityForName:@"Position" inManagedObjectContext:context];
    Position *pos2 = [NSEntityDescription insertNewObjectForEntityForName:@"Position" inManagedObjectContext:context];
    
    step1.position = pos1;
    step2.position = pos2;
    step3.position = pos1;
    
    // temporary proxy object used to modify the ordered to-many relationship "steps":
    NSMutableOrderedSet *tmpMutableSteps = [plan1 mutableOrderedSetValueForKey:@"steps"];
    [tmpMutableSteps addObject:step1];
    [tmpMutableSteps addObject:step2];
    [tmpMutableSteps addObject:step3];
    

    More information:

    You can also set plan1.steps in one “step” like this:

    plan1.steps = [NSOrderedSet orderedSetWithObjects:step1, step2, step3, nil]; // works!
    

    But some accessor methods do not work with ordered relationships:

    [plan1 addStepsObject:step1]; // does not work!
    

    seems to be the “logical step”, but it throws an NSInvalidArgumentException:

    *** -[NSSet intersectsSet:]: set argument is not an NSSet
    

    This seems to be a bug in the auto-generated accessor methods which has already been noticed by other people (e.g. Exception thrown in NSOrderedSet generated accessors). Using the proxy object is a workaround for that problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a set of entity objects in my iOS Core Data database that
I have a Core Data database of about 500 objects. These objects are 'cards'
I have a core data setup that has 2 database entities. For the sake
I have an iPhone app with a Core Data database containing a list of
I have a core data database which has (for now) 2 entities Product and
I have a core data UITableView, the core data managed object has 4 properties
I have a core data database that is filled up with data coming from
I have a core data database and I would like to show the data
I have a huge core data database of longitudes and latitudes for paths on
I have a UITableview cell that gets a tally from a core data database.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.