0

I am so struck with this problem

I have a "Person" Coredata Subclass,

Obviously a Person has a father(Person), mother(Person),Spouse(Person) and Children(List of Persons)

(represented in terms of relationship)

If a person is one of the children of his father he is one of the children of his mother two.

So "children" has to be related to Mother and Father.

I cant do that in Core data, Am I missing anything? Is there a way to solve this problem?

riyaz
  • 1,093
  • 1
  • 8
  • 21
  • 1
    I added a new entity called Marriage NSDate *date; Person *spouse; NSOrderedSet *children; It seems to solve the problem – riyaz Oct 15 '16 at 18:09

1 Answers1

3

If you are using CoreData you should know, that it is a rapper for SQLite, so you need to make your relationsships like you would do in SQL. Person "child" is a n:1 realtion to father and to mother. Model a new Entity for instance MotherToChild where you could do the mapping like normalization in SQL.

weissja19
  • 535
  • 4
  • 11
  • //Person "child" is a n:1 realtion to father and to mother// I am not able to do it. – riyaz Oct 15 '16 at 17:48
  • You have to model the relationships in the entities section of your Coredata editor. Another important point is that you need 2 relationships for every 1:n relation. (See this post for more information: http://stackoverflow.com/questions/12709842/ios-coredata-inverse-relationships-to-itself) – weissja19 Oct 15 '16 at 18:04
  • I clearly understand it, but a person has two relationship to Mother, Father. While the father has a relationship children to a person and the mother has the same relationship to same children which cant be done in core data. Two inverse relationships is not possible for children. – riyaz Oct 15 '16 at 18:06
  • 1
    Okay understood your problem. Have you tried to Model a new Entity for instance MotherToChild where you could do the mapping like normalization in SQL? – weissja19 Oct 15 '16 at 18:13
  • That is what I did :) You can give that as an answer – riyaz Oct 15 '16 at 18:15
  • Okay ;) I edited now the initial answer. Hope it was a help anyway. – weissja19 Oct 15 '16 at 19:24