Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-02-2012, 01:20 PM   #1 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 109
raheel is on a distinguished road
Default Coredata entity relationship with itself with rules

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:

Code:
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..

Code:
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:

Quote:
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:
  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.
  2. How could a child have a relationship with itself? in such a way that :
  3. 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.
  4. 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!
  5. When Quering ParentA.childs that should reveal only 3 child objects - Alpha, Beta, Gamma.
  6. ParentB.Childs should reveal --->> Pi, Gamma, Beta, (3 objects).
  7. If i chose to reveal all childs of a parent with out childs having subchilds,
  8. Parent A should have oNLY 2 - Alpha and Beta
  9. Parent B should have 3 -> Pi, Alpha, Beta.
  10. 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
raheel is offline   Reply With Quote
Old 02-02-2012, 01:53 PM   #2 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Seattle, WA
Posts: 408
RickSDK is on a distinguished road
Default

Its unclear to me what your questions are or what errors you are currently getting. :/
__________________
Check out my apps

RickSDK is offline   Reply With Quote
Old 02-03-2012, 05:04 AM   #3 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 109
raheel is on a distinguished road
Default

Quote:
Originally Posted by RickSDK View Post
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
raheel is offline   Reply With Quote
Old 02-03-2012, 03:51 PM   #4 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Seattle, WA
Posts: 408
RickSDK is on a distinguished road
Default

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.
__________________
Check out my apps

RickSDK is offline   Reply With Quote
Old 02-03-2012, 07:22 PM   #5 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 109
raheel is on a distinguished road
Default

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
raheel is offline   Reply With Quote
Reply

Bookmarks

Tags
coredata, entities, ios, xcode

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 405
16 members and 389 guests
Atatator, chiataytuday, dre, FrankWeller, imac74, ipodphone, jeroenkeij, kukat, LunarMoon, MAMN84, n00b, QuantumDoja, reficul, Retouchable, tim0504, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,675
Threads: 94,124
Posts: 402,909
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Retouchable
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:08 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0