How to work with nested objects
bukshev opened this issue · 2 comments
Hello!
I saw your solution and it became interesting to understand how everything works. With primitive types there is no question, but with complex types it is not very clear. There are 2 questions:
- Let's say we have a ParentClass that has a relationship with one element of type ChildClass (1-to-1 relationship in CoreData model).
- Let's say we have a ParentClass that has an array of elements of the ChildClass type (1-to-many relationship in CoreData Model).
If it's not difficult for you, then I will be grateful to you for expanding the documentation with some simple example.
Thanks in advance for any answer!
@bukshev Thank you for taking the time to look over the package and asking thoughtful questions. Considering this is the first issue created for the repository, I think a celebration is appropriate!
🥳
Now, to address your questions:
I think there are two primary ways to handle related entities:
- Maintain a shallow, 1-to-1 relationship between
UnmanagedModel
s andRepositoryManagedModel
s. This would mean thatUnamangedModel
s would not contain nested child types. - Freely construct
UnmanagedModel
s with any nested relationships. SinceUnmanagedModel.asRepoManaged
,RepositoryManagedModel.create
, andRepositoryManagedModel.update
all give access to theNSManagedObjectContext
, nested or relatedRepositoryManagedModel
s can be created or edited as needed.
I realize that is not a very illustrative response. So, I've created a branch and initialized a project where an example can be made. It might be a while before I can really get into it so feel free to make a PR against the branch with any CoreData model code that you think would be a good example.
https://github.com/roanutil/CoreDataRepository/tree/add-examples-for-relationships
It's been over a year.... That's not a good sign. I do hope to add better examples in the future but not sure when. Feel free to re-open or create a new issue if needed.