Core data NSFetchRequest also fetches children objects of the Entity
core-data, ios, iphone
Solution
If you define Properties as parent entity of Units, then every Units object is also a Properties object. Therefore fetching properties returns also all units.
This is probably not what you wanted. You should just define the relationships between Properties and Units, without setting a parent entity (so that both classes are direct subclasses of `NSManagedObject`).
Remark: I would call the entities Property and Unit, because each instance represents a single property or unit.
Problem
I'm new to iOS dev and Core Data. I have a parent NSManagedObject ``` @class Units; @interface Properties : NSManagedObject @property (nonatomic, retain) NSString * descr; @property (nonatomic, retain) NSString * address; @property (nonatomic, retain) NSString * city; @property (nonatomic, retain) NSString * state; @property (nonatomic, retain) NSString *zipCode; @property (nonatomic, retain) NSString * imageKey; @property (nonatomic, retain) NSString * numberOfUnit; @property (nonatomic, retain) NSData * thumbnailData; @property (nonatomic, strong) UIImage * thumbnail; @property (nonatomic) double orderingValue; @property (nonatomic, retain) NSSet *units; ``` And a Child: ``` @class Properties; @interface Units : Properties @property (nonatomic, retain) NSString * unitDescr; @property (nonatomic) int16_t unitNumber; @property (nonatomic, retain) Properties *property; ``` When I fetch the Parent Properties with this method to display the parent Properties objects in a tableview: ``` - (void)loadAllItems { if (!allItems) { NSFetchRequest *request = [[NSFetchRequest alloc] init]; NSEntityDescription *e = [[model entitiesByName] objectForKey:@"Properties"]; [request setEntity:e]; NSSortDescriptor *sd = [NSSortDescriptor sortDescriptorWithKey:@"orderingValue" ascending:YES]; [request setSortDescriptors:[NSArray arrayWithObject:sd]]; NSError *error; NSArray *result = [context executeFetchRequest:request error:&error]; if (!result) { [NSException raise:@"Fetch failed" format:@"Reason: %@", [error localizedDescription]]; } allItems = [[NSMutableArray alloc] initWithArray:result]; } } ``` I run in to a problem where the core data context fetches the child objects of the Parent Entity. I just want to return the Parent Objects. For example, If I have a property with 3 units, the properties tableview should display just 1 row but it is displaying 4 rows (1 parent and 3 childs). How do I just return the parent objects? Thanks.