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 7694287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:17:07+00:00 2026-05-31T21:17:07+00:00

Im new with CoreData and have a relatively good hold on it, except now

  • 0

Im new with CoreData and have a relatively good hold on it, except now Im starting to look at relationships and need a little help.

An issue in my app made me think about it, I have two entities, TableInfo and PersonInfo.

A table can have many people sit at it, but a person can only sit at one table. So I know it would be a one to many relationship in that respect and it makes real world sense as well.

Anyway, in my app, I add a table to my person, so I basically say, this persons sits at this table. However, how do I handle, if I then go and delete the table I have already given to a person?

I figured relationships might come into play here, but I have never worked with them before so its tricky for me to understand where to go here.

If anyone knows of any good tutorials which will help with this issue or details core data relationships, or you can help I would very much appreciate it, thanks, or let me know if Im barking up the wrong tree with relationships for this issue.

Thanks!

  • 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-31T21:17:08+00:00Added an answer on May 31, 2026 at 9:17 pm

    This is a good situation where you would use Core Data relationships.

    The usual Apple Documentation (https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CoreData/HowManagedObjectsarerelated.html) will give you a good grasp of how it works.

    In short, for a relationship you can specify a Delete Rule.
    In your case, you would probably choose "Nullify". That means, if you delete the table, the table-property of your Person will become null, indicating that your person no longer sits on a table.

    Edit: You could also specify "Cascade" which would delete the person together with the table (rather pointless, but slightly amusing thought). Or, you can specify "Deny", which will abort a deletion if at least one person still sits on the table.

    Example:

    Assume you have two entities, "TableInfo" and "PersonInfo". "PersonInfo" has a relationship called "table", "TableInfo" has a relationship called "persons". "table" is a to-one relationship with "TableInfo" as its target. "persons" is a to-many relationship with "PersonInfo" as its target.

    Now set the "Inverse Relationship" of "persons" to "table". The "Inverse Relationship" of "table" will bet set to "persons" automatically.

    If you let CoreData generate your model subclasses (you should!), you will end up with a class like this:

    @interface TableInfo : NSManagedObject
    
    @property (nonatomic, retain) NSSet *persons;
    @end
    
    @interface TableInfo (CoreDataGeneratedAccessors)
    
    - (void)addPersonsObject:(PersonInfo *)value;
    - (void)removePersonsObject:(PersonInfo *)value;
    - (void)addPersons:(NSSet *)values;
    - (void)removePersons:(NSSet *)values;
    

    As you can see, CoreData automatically creates appropiate accessors for you. Just use them.

    You can now do the following:

    TableInfo* myTable = [NSEntityDescription insertNewObjectForEntityForName:@"TableInfo" inManagedObjectContext:self.managedObjectContext];
    
    PersonInfo* myPerson = [NSEntityDescription insertNewObjectForEntityForName:@"PersonInfo" inManagedObjectContext:self.managedObjectContext];
    
    [myTable addPersonsObject:myPerson];
    NSLog(@"%@", myPerson.table); // will be your TableInfo object "myTable"
    

    In short, please read the documentation I linked above, there are plenty of examples there and on the internet. Feel free to ask questions on SO, but for "basic" needs the tutorials on the internet will be more complete and helpful.

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

Sidebar

Related Questions

I am new on iphone development and I have problem with CoreData. I hardly
I'm starting with CoreData and I have a question : I have an array
I have a CoreData / NSPersistentDoc app. It works fine. I added a new
I have made a new split view iPad app using CoreData. All I have
I have a strange issue with delete rules in coredata. My data model is
I am starting out with CoreData and have managed to incorporate it into my
I have started playing around with CoreData and taking a new project with CoreData
I am new to core data .I have already performed insert and delete operations
I am new to Objective C and iPhone development. I am using CoreData on
I need a tabbed application with core data persistence. when i create a new

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.