Core Data inheritance vs no inheritance
i’m having some issues with core data, so i hope that someone will be able to help me 🙂
First problem, i have a data model that looks like this :
Entity P (A) <----> Entity R / | \ / /\ \ / / | \ \ C D E F G
All my entities inherit from the same entity “P” because they need a common attribute and a common relationship (“A” and “R”)
The problem i am getting is that core data uses generates only one sqlite table for all the entities when you use inheritance. In my case it means that my database will have only 1 table for all the datas. I did some research and i saw that it creates performance issues (moreover all my entities attributes are transients and during willSave their values are aggregated+encrypted into one NSData stored in “A”, so i won’t be able to use predicate to filter and improve SELECT performances). So i decided to remove “P”, and to add “A” into “C”, “D”…, “G”. The problem is with “R”, because before i had only one inverse relationship in it, and now i need to create one each time i create a new kind of entity.
So i would like to remove all the inverse relationships, is it possible?
Sometimes i need to create managed object with a nil context, and i insert them into the context later, this is probably why the inverse relationship are not automatically set by core data if i set the non-inverse before the insertion in the MOC right ?
Anyway i never need the inverse, so can i avoid defining them even if i get a warning ?
2nd problem, in specific situations i need to create a new “R” and to assign it to “C”, “D”,.., “G” during the MOC save. So i would like to use willSave but, i don’t know if the created entity will be saved. If the MOC does a simple loop over the “insertedObjects” / “updatedObjects” / “deletedObjects”, and for each object it calls willSave, does the save, and then calls didSave, it means that i’m going to modify the array on which it is iterating, and then it should crash no?
- How to Deal with Temporary NSManagedObject instances?
- Objective c - Core Data saving approach
- Core Data predicate : unimplemented SQL generation for predicate
- Core data not saving my data
- How to add unique constraints for some fields in Core Data
- How come I can cast to NSManagedObject but not to my entity's type?
2 Solutions Collect From Internet About “Core Data inheritance vs no inheritance”
As you and I both independently found out the hard way, be very, very careful with entities which inherit from each other. I too found Core Data tends to make one giant table containing all the fields for the base entity and all entities which derive from it, so any given entity contains the fields for every potential entity from its furthest ancestor downwards. Very, very slow and expensive.
I highly recommend only having the entity classes themselves inherit from each other, and mirroring the properties of the base class in all entities instead, without any actual inheritance in the managed object model itself.
Core data is not a wrapper around your sql tables. It deals with object graph and its persistence. SQLite store is just one way of persisting it. Check this up.
Prevent Core Data From Combining Entities into One Table
- UICollectionView doesn't contain UICollectionViewCell in IB
- Facebook iOS SDK 3.x feed dialog is gone?
- Lazy loading variable error
- iOS, detect ad-hoc from code
- Significant Location Changes – What guarantees do we have?
- How to upload image with parameters using Alamofire in Swift
- NSCalendar to Display Weekday
- How can I create a horizontal gradient background for my iOS nav bar?
- What is the limit (if any) to the tuple cardinality in Swift?
- Best option for supplying Quadtree GPS Data to an app?
- Swift – How Can I use 'shouldChangeTextInRange' with Firebase for real time searching?
- what if when two UITableView in one ViewController and one with custom cell refrence and another is a simple
- Objective-c: start app with second view with a navigation bar
- Twitter SDK on iOS with standard UI
- Different Navigation Bar Button Items in different child viewcontrollers from two container views?