CoreData - one-to-many modeled relationship comes out as one-to-one

后端 未结 1 737
南笙
南笙 2020-12-09 16:45

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, whic

相关标签:
1条回答
  • 2020-12-09 17:34

    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 讨论(0)
提交回复
热议问题