I’m guessing this is a basic question and hopefully someone will be able to point me in the right direction to some sample code, so my question….
I want/have created a core data model that has a parent child relationship, one to many, what I would like to know is what is the correct way to insert child records if the parent already exists. What I’m struggling to understand is how the parent relationship is created when only inserting child records.
Hopefully this makes sense, thanks for any help.
Inverse relationships enable Core Data to propagate change in both directions when an instance of either the source or destination type changes. Every relationship must have an inverse. When creating relationships in the Graph editor, you add inverse relationships between entities in a single step.
What you need to know is that Core Data is not a database. That said, when working with Core Data it acts as a relational database hence the confusion. Core Data is a persistence solution for Apple's platforms and it supports several types of persistent stores, including SQLite.
Core Data is an object graph and persistence framework provided by Apple in the macOS and iOS operating systems. It was introduced in Mac OS X 10.4 Tiger and iOS with iPhone SDK 3.0. It allows data organized by the relational entity–attribute model to be serialized into XML, binary, or SQLite stores.
Here You have a series of 3 tutorials: RayWenderlich: Core Data Tutorial
Here a sample app: iPhoneCoreDataRecipes with a more complex data model
Here a Core Data tutorial – One to Many Relationship
Sorry I not respond to your question in his totally. I'm also starting with Core Data, so If You find a good intermediate tuturial, please let me know.
EDIT: A nice article: Core Data Class Overview
So you'll have Parent and Child. Child will contain a Parent *parentobject while Parent will contain a NSSet *children. Whenever you set the relationship correct in the Datamodel the relationship will be applied automatically when you fill the children set with Child objects.
Please check Articles here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With