To understand a lot of core data, I'm working to all sorts of likely scenarios to develop a scalable model, to secure future.. in a way..
Among that I have a situation, there are many ways to do it, i was looking for a most efficient way.
What I'm working on:
Relationship: Parent (to-many)
Relationship: Child (to-many)
Relationship: Controller (to-one)
Relationship: Parent (to-one; inverse)
Now please consider these random formulae..
A (parentEntity) = Alpha (child) + Beta (child) + Gamma (child)
B (parentEntity) = Pi (child) + Gamma (child) + Beta (child)
Having A and B as parent Objects and adding these objects were no problem at all with their respective Child sets,
Worth noting is that, Beta child exists in both Parent entities.
heres the change:
Gamma (child) = [Alpha (child) + Beta (child)] / 2
Both Alpha and Beta child objects are the same in both entities, hence there can ONLY BE ONE!
It seemed pretty easy to just ad Gamma as a PARENT and add those two as their child and compute. But that (though was the easy way out) wasn't good for the future proofing.. too many objects is always a bad idea..
Hence, i wanted to find a relationship that a ChildEntity would have ... with kinda itself(if it can). For example a Child entity of Gamma would get its value automatically deriving from Alpha child and Beta child.
There are certain conditions that all these relationships should satisfy:
[*]One Controller Object can Have ONLY ONE "TYPE" of Child Object. There can be many Parent objects for it. For example, if the Controller has created a Parent A, he could add Alpha and Beta Child, when the same controller creates Parent B, he can add New Pi child but not Beta as it already exists, he should "choose" it.. i could add some kinda identifier unique per child. How can i set a rule to accomplish this on NewInsert.
[*]How could a child have a relationship with itself? in such a way that :
[*]Parent should can Have ONE ONE Gamma child Which intern calculates its value based on values from Child Alpha and CHild Beta, which are, again, Unique per Controller.
[*]heres an model i created, but I don't really know how would i add a Child (alpha) and CHild (Beta) as subchilds of Child Gamma!
[*]When Quering ParentA.childs that should reveal only 3 child objects - Alpha, Beta, Gamma.
[*]ParentB.Childs should reveal --->> Pi, Gamma, Beta, (3 objects).
[*]If i chose to reveal all childs of a parent with out childs having subchilds,
[*]Parent A should have oNLY 2 - Alpha and Beta
[*]Parent B should have 3 -> Pi, Alpha, Beta.
[*]Lastly when i decide to export or convert this data into xml, it shouldn't be as confusing..
As someone new to core data I'm finding it difficult to go away form sqlite kinda thinking, but I'm trying.
Any help is appreciated