Core Data combined Query

Posted by Chris Summer on Stack Overflow See other posts from Stack Overflow or by Chris Summer
Published on 2010-05-10T14:10:09Z Indexed on 2010/05/10 14:14 UTC
Read the original article Hit count: 157

Filed under:
|

Hey, i have question related to CoreData. My iphone project has 2 Entities, Organisation and Brand with a 1 to many "BrandsToOrg" relationship and inverse.

So my project has a Mapview, where you can see all the Organisations and a little subview when you click on those Organisations.At the subview there is a "show Brands" Button, which should init a new TableView who only shows the brands belong to the seleceted organisation. Any ideas how i can code that?

thx

 NSPredicate *predicate = [NSPredicate predicateWithFormat: @"(TitleMedium == %@)",@"Rock Antenne"];????
NSFetchRequest *request = [[NSFetchRequest alloc] init];

NSEntityDescription *entity = [NSEntityDescription entityForName:self.entityName inManagedObjectContext:managedObjectContext]; [request setEntity:entity];

// If a predicate was passed, pass it to the query if(predicate != nil) { [request setPredicate:predicate]; }

// If a sort key was passed, use it for sorting. NSString *sortKey=@"TitleMedium"; BOOL sortAscending=YES; if(sortKey != nil) { NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:sortKey ascending:sortAscending]; NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil]; [request setSortDescriptors:sortDescriptors]; [sortDescriptors release]; [sortDescriptor release]; }

NSError *error;

NSMutableArray *mutableFetchResults = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];

[request release]; [self setEntityArray:mutableFetchResults];

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c