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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:56:46+00:00 2026-05-25T21:56:46+00:00

I am trying to save a new Object to my context, that will have

  • 0

I am trying to save a new Object to my context, that will have a foreign key reference (relationship many-to-many) to an object already in the database.

How can I set the relationship of this new Object to save it to the database?. I tried fetching that object and then setting it in the relationship, but that causes an error when saving the context that comes as null.

I also tried recreating it as a new object, thinking core data would not create a new object but just add the relationship, however it did create the new Object.

How can I save this object?

  • 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-25T21:56:47+00:00Added an answer on May 25, 2026 at 9:56 pm

    You have to set the object in the relationship from your new object, the inverse relationship will then be set for you.

    So, you need to figure out what is causing the error you are seeing.

    In CoreData objects generated from mogenerator, the code to add a single object to a relationship set accesses a mutable set from the object property:

    NSMutableSet *result = [self mutableSetValueForKey:@"rounds"];
    

    Then you can add your existing object to that set, and try saving the new object.

    Alternatley, CoreData for any ManagedObject generates a method:

    - (void)addRoundsObject:(Round*)value_;
    

    If you use that method it should also add the object correctly.

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

Sidebar

Related Questions

Does it make sense to create new object before trying to save object that
I'm trying to save a PDF file to SQL Server and I already have
I am trying to save data to a database on a button push, but
I am trying to save a record which has a many-to-one property mapping. I
I am trying to save a custom object as a user setting in a
I have a script that creates files on multiple threads. Occassionally, I will get
I'm trying to carry over player_id and save to the Stakes table referencing that
I have a repository class that defines some basic Get/Save/Delete methods. Inside these, I
I have a view controller that i'm trying to push onto the navigation stack.
I have been trying to create a simple app that parse an entire channel

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.