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

  • SEARCH
  • Home
  • 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 6612459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:06:03+00:00 2026-05-25T20:06:03+00:00

I’m creating an app and trying to use core data, because it seems like

  • 0

I’m creating an app and trying to use core data, because it seems like it’s the objective-C approved way to create a data storage system. The use case I have involves “many to many” relationships, like you’d normally see in a standard SQL system. I understand that objective C is not a database and works differently. I’ve also reviewed the documentation here:

http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/CoreData/Articles/cdRelationships.html#//apple_ref/doc/uid/TP40001857-SW10

And several other places. And yet, I’m still having trouble. Can someone explain to me what you would do if you have a use case where you’d need to use a SQL cross reference table? For example:

Managers | Employees

Manager may have several employees, but the employees might also have several manager. In SQL, I’d create a cross reference table and then use that.

Example: http://www.tomjewett.com/dbdesign/dbdesign.php?page=manymany.php

Can someone explain how you could do that in Core data?

According to the core data documentation, they say this:

“You define a many-to-many relationship using two to-many relationships. The first to-many relationship goes from the first entity to the second entity. The second to-many relationship goes from the second entity to the first entity. You then set each to be the inverse of the other. (If you have a background in database management and this causes you concern, don’t worry: if you use a SQLite store, Core Data automatically creates the intermediate join table for you.)”

But, besides “not being worried,” I don’t know how this could possibly work?

  • 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-05-25T20:06:04+00:00Added an answer on May 25, 2026 at 8:06 pm

    Peter: “I have nine bosses, Bob.”
    Bob: “Say again?”
    Peter: “Nine.”

    Take your brain out of the database. Do not ask how to access a cross-reference table. Ask how to find the employees for a manager or the managers for an employee.

    If you use a custom subclass of NSManagedObject, you can declare the properties as documented. Then you can simply say:

    NSSet *mgrsEmployees = mgr.employees;
    NSSet *employeesMgrs = employee.managers;
    

    That will not give you all the employees and all the managers, only all the employees for that manager and all the managers for that employee. To change relationships:

    [mgr addEmployeesObject:newEmployee];
    [newEmployee addManagersObject:mgr]; // not necessary, automatic if you define inverse
    
    [mgr removeEmployeesObject:transferredEmployee];
    [transferredEmployee removeManagersObject:mgr]; // not necessary
    [newMgr addEmployeesObject:transferredEmployee];
    [transferredEmployee addManagersObject:newMgr]; // not necessary
    

    You only need to do either one of each pair of statements, and it will implicitly do the other, provided you have defined managers and employees as inverses of each other.

    If you don’t use a custom subclass, accessing is a little more verbose

    NSSet *mgrsEmployees = [mgr valueForKey:@"employees"];
    NSSet *employeesMgrs = [employee valueForKey:@"managers"];
    
    NSMutableSet *changeMgrsEmployees = [mgr mutableSetValueForKey:@"employees"];
    [changeMgrsEmployees addObject:newEmployee];
    // not necessary
    NSMutableSet *changeEmployeesMgrs = [employee mutableSetValueForKey:@"managers"];
    [changeEmployeesMgrs addObject:mgr];
    

    Etc.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace

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.