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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:59:31+00:00 2026-05-21T22:59:31+00:00

I have two core data entities, Articles and Favorite . Articles has To-Many relationship

  • 0

I have two core data entities, Articles and Favorite. Articles has To-Many relationship to Favorite. First, I inserted all Articles object successfully.

Now, I’m trying to insert ArticleID in “Favorite” entity but I cant. Either the record is inserted with an empty relationship or it is inserted with new record in “Articles” entity.

I think that I should be getting the related record in Articles entity first and then using it to insert in Favorite but I’m not sure how to do this. My current code:

NSManagedObjectContext *context =[appDelegate managedObjectContext] ; 
favorite *Fav =[NSEntityDescription insertNewObjectForEntityForName:@"favorite" inManagedObjectContext:context];
Articles * Article = [NSEntityDescription insertNewObjectForEntityForName:@"Articles" inManagedObjectContext:context];

NSError *error;

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; 
NSEntityDescription *entity = [NSEntityDescription 
                               entityForName:@"Articles" inManagedObjectContext:context];  
[fetchRequest setEntity:entity]; 
NSPredicate *secondpredicate = [NSPredicate predicateWithFormat:@"qid = %@",appDelegate.GlobalQID ];
NSPredicate *thirdpredicate = [NSPredicate predicateWithFormat:@"LangID=%@",appDelegate.LangID]; 
NSPredicate *comboPredicate = [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray arrayWithObjects: secondpredicate,thirdpredicate, nil]]; 
[fetchRequest setPredicate:comboPredicate];
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
for (NSManagedObject *info in fetchedObjects) { 
        // ?????????????????????????

    }

}

Any suggestions would be appreciated.

  • 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-21T22:59:32+00:00Added an answer on May 21, 2026 at 10:59 pm

    I solved it by creating new Article object:

    Articles *NewObj = [fetchedObjects objectAtIndex:0];
    

    and use it to insert relationship :

        [Fav setFavArticles:NewObj];
         [NewObj setArticlesFav:Fav];
    

    thanks very much TechZen..

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

Sidebar

Related Questions

I have two Core Data entities: Parent and Child . Parent has to-many relationship
In my Core Data model I have two entities: List and Patient. List has
I'm using core data in my app. I have two entities that are related:
I've got a window set up with two NSTableViews. In Core Data I have
I have a problem with Core Data which has left me at the end
Consider that i have two entities with following relationship: Entity A <-->> Entity B
Say I have core data objects of type obj that has a property propertyA
We have a project that has two one to many relationships. We encounter a
I've got a Core Data entity called Card which has a relationship info to
Basically I have three different Core Data entities ( A , B , C

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.