Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem with property inherited from parent entity
    text
    copied!<p>I'm trying to keep traveling route in core data and here is my data model. I have entity <strong>Coordinate</strong> keeping latitude and longitude in double, then I created <strong>Locatable</strong> entity and make relation between these two entities.</p> <pre><code>Coordinate &lt;-&gt; Locatable </code></pre> <p>then I have <strong>POI</strong> entity inherited <strong>Locatable</strong> these <strong>POI</strong> representing my route. finally I have <strong>Destination</strong> entity inherited <strong>POI</strong> using as my destination point</p> <pre><code>Coordinate &lt;-&gt; Locatable | V POI | V Destination </code></pre> <p>My <strong>Route</strong> class have points as one-to-many relation with these <strong>POI</strong> and destination as one-to-one with <strong>Destination</strong>. Problem occur when I try to get my <strong>POI</strong> collection for create route with MKPolylineView, when I call route.points I also get my destination point with those POI. I know core data create big Locatable for both POI and Destination, but this behavior isn't logically right my destination point shouldn't show up with points. Is this right behavior or I missing something.</p> <p>Quite complicated to explain if I miss some important information please tell me.</p> <p><strong>Updated for more clarify</strong></p> <p>I have Route entity with one-to-one with Destination as destination and one-to-many with POI as points(which I using as my traveling path)</p> <p>When I add destination </p> <pre><code>route.destination = destination_obj </code></pre> <p>it also show up in</p> <pre><code>route.points </code></pre> <p>which doesn't right because these two property serve two different purpose (one for making traveling path, another for pre calculate some data). Is this behavior have any document or explanation ?</p> <p><strong>Added small data model and code sample so every one can reproduce this</strong> Make 3 entity</p> <pre><code>Family - int generation - parents as to-may relation to Parent and family as inverse - child as to-one relation to Child and family as inverse Parent - String name - family to-one relation to Family Child : Parent </code></pre> <p>Here is my code</p> <pre><code>Family *fam; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Family" inManagedObjectContext:self.managedObjectContext]; NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; [fetchRequest setEntity:entity]; NSArray *meters = [self.managedObjectContext executeFetchRequest:fetchRequest error:nil]; if ([meters count] &gt; 0) { NSLog(@"found"); fam = [meters lastObject]; fam.generation = [NSNumber numberWithInt:[fam.generation intValue] + 1]; } else { NSLog(@"new"); fam = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:self.managedObjectContext]; fam.generation = [NSNumber numberWithInt:1]; [self saveContext]; }; NSLog(@"There are %d paren", [fam.parents count]); for (Parent *p in fam.parents) { NSLog(@"name : %@", p.name); } Child *child; if (!fam.child) { child = [NSEntityDescription insertNewObjectForEntityForName: [[NSEntityDescription entityForName:@"Child" inManagedObjectContext:self.managedObjectContext] name] inManagedObjectContext:self.managedObjectContext]; fam.child = child; } fam.child.name = [NSString stringWithFormat:@"child number %d", [fam.generation intValue]]; NSLog(@"There are %d parent after adding one child", [fam.parents count]); Parent *parent = [NSEntityDescription insertNewObjectForEntityForName: [[NSEntityDescription entityForName:@"Parent" inManagedObjectContext:self.managedObjectContext] name] inManagedObjectContext:self.managedObjectContext]; parent.name = [NSString stringWithFormat:@"parent number %d", [fam.generation intValue]]; [fam addParentsObject:parent]; NSLog(@"There are %d parent after add parent", [fam.parents count]); for (Parent *p in fam.parents) { NSLog(@"name : %@", p.name); } [self saveContext]; </code></pre> <p>in short I create family and add one child and one parent to this family and print out some output in the first run I got this result</p> <pre><code>2011-08-27 19:06:28.271 child[2015:207] new 2011-08-27 19:06:28.276 child[2015:207] There are 0 paren 2011-08-27 19:06:28.278 child[2015:207] There are 0 parent after adding one child 2011-08-27 19:06:28.279 child[2015:207] There are 1 parent after add parent 2011-08-27 19:06:28.280 child[2015:207] name : parent number 1 </code></pre> <p>which is what I expected, then I rerun the app again and this what the weird thing occur</p> <pre><code>2011-08-27 19:08:12.383 child[2035:207] found 2011-08-27 19:08:12.386 child[2035:207] There are 2 paren 2011-08-27 19:08:12.387 child[2035:207] name : parent number 1 2011-08-27 19:08:12.388 child[2035:207] name : child number 1 2011-08-27 19:08:12.389 child[2035:207] There are 2 parent after adding one child 2011-08-27 19:08:12.390 child[2035:207] There are 3 parent after add parent 2011-08-27 19:08:12.390 child[2035:207] name : parent number 1 2011-08-27 19:08:12.391 child[2035:207] name : parent number 2 2011-08-27 19:08:12.391 child[2035:207] name : child number 2 </code></pre> <p>child entity is included in parents property. This is some kind of my misconception or this is a bug on SDK ?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload