Reputation: 1647
I have a question regarding the way you create relationships in Core Data.
I will explain with an example:
Let's say I have 3 entities. Motor, Pump and Warning.
Motor and Pump can send warnings.
The Warning entity will store all the warnings from Motor and Pump.
So the question is... Is it really necessary to create so many relationships in Warning for Motor and Pump? When I want to add another entity that can send warnings, I will need another relationship.
Wouldn't this be bad design?
Hope I'm understandable.
Thanks.
Upvotes: 0
Views: 162
Reputation: 22334
Yes, this is normal. A better, more structured approach is to have a base entity for Motor and Pump, let's call it Component. This Component entity has the relationship with Warnings and the warning entity has an inverse relationship to Component.
You then set your Motor and Pump to be descendants of the Component entity and everything is good. One single relationship / inverse relationship between Component and Warning.
Upvotes: 2
Reputation: 45598
This is standard and good practice. Core Data requires inverse relationships for everything to maintain its object graph. (Well, technically you don't have to add them, but you then have to do extra work yourself).
So don't worry, it's normal for your often-used entities to have many inverse relationships on them.
Upvotes: 2