Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

Coredata entity relationship with itself with rules

raheelraheel Posts: 109Registered Users
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:

ControllerEntity {
title: String;
Relationship: Parent (to-many)
}

ParentEntity {
title: String;
Relationship: Child (to-many)
Relationship: Controller (to-one)

}

ChildEntity {
Value: NSNumber;
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:

[LIST=1]
[*]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..
[/LIST]
image


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
Post edited by raheel on

Replies

  • RickSDKRickSDK Posts: 637Registered Users
    Its unclear to me what your questions are or what errors you are currently getting. :/
  • raheelraheel Posts: 109Registered Users
    RickSDK;406341 said:
    Its unclear to me what your questions are or what errors you are currently getting. :/
    My question is, is that a right approach? specially for a Child --->>Child relationship that would satisfy all those conditions..

    Till now i dont get errors, but in the background, i know little thats going on.. I just dont want to create unnecessary relationship/entities here
  • RickSDKRickSDK Posts: 637Registered Users
    hmmm... still a little hazy on what you are trying to do, but here's some info for you;

    The only true relationship between any two tables is "One-to-Many". And this means that any parent table can have mutliple related children, but each child element has only a single parent.

    Now if you instead need a "Many-To-Many" relationship, then you need to create an intersection table with many-to-one relationships to both the child and parent.

    If you are still stuck, maybe you can present some sameple data that you are working with.
  • raheelraheel Posts: 109Registered Users
    Im looking to establish relationships between "formulae" and its "variables" in a super effective way...

    And I'd want this behavior to be dynamic, to be established at runtime, hence I'm having a data model that supports it would be very very helpful.

    Consider einsteins equation here..

    I could add Energy(einsteins) as ParentObject, it has two child entities - mass and lightspeed. (E = mc^2)

    Ofcourse, calculation part would be done later.. But,

    What If the child (mass) would be derived from another two variables
    Mass = Volume * Density. In this case, all three are essentially "child" entities.

    Which is why i add a to-many relationship child ----->>child and named it "sub child" though it should be "associatedChild" relationship.

    When fetching and Einstain, I would want Mass to be replaced by Volume X Density. or perhaps return those two child, even though einstein isn't directly related with Volume and density.

    Another could be Velocity as a ParentObject, which will have U(early speed), Aceleration and Timetaken as child entities. (v= u+at)
    Then again, all of them can be child entities, With some math relationships with each other reducing the parentEntity to only be a fancy name .. like "bernoilli's principle," pythagoras . .etc..

    Basically i want to establish physical variable relationships with themselves without the need to have a "Parent" entity.

    I hope you get the point, i really need help here..
    thanks :)
Sign In or Register to comment.