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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:53:33+00:00 2026-05-27T04:53:33+00:00

I am new to Core Data modeling, and I am having a hard time

  • 0

I am new to Core Data modeling, and I am having a hard time understanding how one-to-many relationships work.

I have a parent entity called Task, which can have several instances of Comment entity. I modeled it like this: on Comments, a relationship to Task called task with the Task entity a destination. On Task, a relationship called comments, with Comment as its destination, and both relationships are each others inverse.

Not defining an inverse results in either warnings or error messages. While modeling this way works, I’ve noticed that once I create a second comment for a given Task, the first is replaced (one-to-one relationship).

What would be the correct way to tell the Core Data Model that this relationship allows many comments in one Task?

Also, since CoreData seems to manage primary keys on its own, how would I create an NSPredicate to retrieve all comments for a given Task?

Thanks for any suggestions!

  • 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-27T04:53:34+00:00Added an answer on May 27, 2026 at 4:53 am

    First of all you need to set the plural option in the Task entity, select it in your .xdatamodeled and select the relationship property of Task entity to comments you should be able to see thisenter image description here

    there is a plural option be sure to check that out. You must recreate your NSManagedObject if your using generated classes and also if your using sqlite store you must delete and rebuild so it will not complain about the new schema not being the same with the old one.

    To check if you have a one to many relationship your Task entity should have a property called comments which is a class type of NSSet not Comments.

    If you want to retrieve all comments for a given task you need to iterate the NSSet(comments) property of that task.

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

Sidebar

Related Questions

As an answer to a question I asked yesterday ( New Core Data entity
I'm quite new with Core Data, and I'm having an issue that I don't
I'm new to core data and having some difficulty finding any information about sorting
So I'm fairly new to Core Data and KVO, but I have an NSManagedObject
I am new to Core Data. I have noticed that collection types are not
I have a view that creates a new core data managed object, and fills
I am fairly new to Core Data and have run into an issue which
Im new to using core data and having really basic problems. Im trying to
I have an Entity Item in Core Data. Item has two attributes: name and
I'm brand new to core data, and I'm having a bit of trouble. I'm

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.