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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:23:22+00:00 2026-06-11T01:23:22+00:00

I have a One-To-Many relationship set up in core data. I can View/Add/Remove objects

  • 0

I have a One-To-Many relationship set up in core data. I can View/Add/Remove objects from the ‘Main’ Entity, however now I want to View/Add/Remove objects to the many ‘Subs’ entity which should have separate lists of Subs objects for each Main entity.

I have tried this code:

NSManagedObjectContext *context = [[DataSingleton sharedSingleton] thisMain].managedObjectContext;
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
                               entityForName:@"Subs" inManagedObjectContext:context];
[fetchRequest setEntity:entity];

NSError *error;
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];

wolArray = [NSMutableArray arrayWithArray:fetchedObjects];

[[DataSingleton sharedSingleton] thisMain] is the Main that i’m trying to get the Subs for. Am I doing this wrong?
It just seems to give me all the Subs for all the Mains.

Now it is possible that maybe i’m adding them wrong, and they are not getting added to a Subs off of a Main (If thats even possible?)

This is how I’ve added them:

NSManagedObjectContext *context = [[DataSingleton sharedSingleton] thisMain].managedObjectContext;
Subs *subsInfo = [NSEntityDescription
                                insertNewObjectForEntityForName:@"Subs"
                                inManagedObjectContext:context];
subsInfo.name = [newDevice objectForKey:@"name"];
subsInfo.address = [newDevice objectForKey:@"address"];
subsInfo.post = [newDevice objectForKey:@"post"];
NSError *error;
if (![context save:&error]) {
    NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
}
  • 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-11T01:23:24+00:00Added an answer on June 11, 2026 at 1:23 am

    If thisMain is a “Main” object and subs is the one-to-many relation from “Main” to “Subs”, then you can just do

    NSArray *thisSubs = [thisMain.subs allObjects];
    

    to get an array of all “Subs” for thisMain. Do do not need a fetch request for that.

    For your second task you need to define an inverse relation “main” from “Subs” to “Main”. When you have created the new “Subs” object subsInfo, then

    subsInfo.main = thisMain;
    

    adds it to the main object.

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

Sidebar

Related Questions

In this test Core Data project, I have a one to many relationship from
I have a core data entity which has an exclusive one to many relationship
I have a core data entity A that has a one-to-many relationship with entity
I'm working with Core Data and a many-to-many relationship: a building can have multiple
I have a 1-to-many relationship in my example app, taken from the Core Data
I have a core data model which includes an entity with a to-many relationship.
I have a one to many relationship in my core data model. I need
Here, the Sencha team explains how to have a one to many relationship: http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Store
I have a simple one-to-many relationship. I would like to select rows from the
I have core data model with two entities that have a many-to-many relationship with

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.