I have two core data entities. Lets call them AAA and BBB.
BBB contains a relationship to AAA, one to one.
When I create a new BBB entry, I do (at this point myA is one entry on AAA):
BBB *item = nil;
NSFetchRequest *request = [[NSFetchRequest alloc] init];
request.entity = [NSEntityDescription entityForName:@"BBB" inManagedObjectContext:context];
request.predicate = [NSPredicate predicateWithFormat:@"(relation == %@)", myA];
NSError *error = nil;
item = [[context executeFetchRequest:request error:&error] lastObject];
[request release];
if (!error && !umItem) { // if there's no item, create a new one
item = [NSEntityDescription insertNewObjectForEntityForName:@"BBB" inManagedObjectContext:context];
item.relation = myA; // to create a relation from BBB to AAA
}
at some point in time, I have just a list of BBB objects. Remember that each BBB object has a property called relation pointing to AAA.
Now, how do I retrieve AAA?
Is it enough to do
AAA *myAAA = (AAA*)myBBB.relation;
is this relation the object itself on AAA?
how do I do that?
thanks
Yes, by calling
myBBB.relation;(dynamic typing is not needful ifrelationis of typeAAA) you will get object of classAAAornil. Ifrelationis not optional then beforecommittingchanges you should define that relationship to all updated/new objects.