mercredi 21 mai 2014

iOS - données de base : aller chercher l'entité abstraite et filtre par des relations d'entités héritées - Stack Overflow


I have data model, with 4 entities: 1. abstract entity "Term" 2. two inherited entities from "Term" - "Section" and "Type" with defined relations to "Seminar" Entity


Here is my model (can't attach image here due to low reputation): core data model


I'm fetching entity "Term" and everything was fine. How can I write predicate to fetch entities where in inherited entities set "seminars" count > 0 ? [NSPredicate preditcateWithFormat:@"seminars.@count > 0"] of course isn't working, because there is now definition of this relation in abstract "Term".


I've allready tried to move relationships "seminar" to abstract "Term", but I can't figure out how to define relations from "Seminar" entity to "Type" end "Section".


BTW, I'm using fetchedResultController in such way for UITableView cells/section/updates/notifications magic. I can filter results programmatically and fill controller model myself, but if there is any way to stay in core data paradigm it will be great.


In some moment Xcode get crazy and crashed until I've discarded all changes to the model.


My code is rather simple:


NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];

NSEntityDescription *entity = [NSEntityDescription entityForName:@"Term" inManagedObjectContext:self.managedObjectContext];
fetchRequest.entity = entity;

fetchRequest.fetchBatchSize = 20;

NSArray *sortDescriptors = @[[[NSSortDescriptor alloc] initWithKey:@"vid" ascending:NO],
[NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)]];

fetchRequest.sortDescriptors = sortDescriptors;

NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"vid" cacheName:CACHE_NAME];

Thanks for help.



I have data model, with 4 entities: 1. abstract entity "Term" 2. two inherited entities from "Term" - "Section" and "Type" with defined relations to "Seminar" Entity


Here is my model (can't attach image here due to low reputation): core data model


I'm fetching entity "Term" and everything was fine. How can I write predicate to fetch entities where in inherited entities set "seminars" count > 0 ? [NSPredicate preditcateWithFormat:@"seminars.@count > 0"] of course isn't working, because there is now definition of this relation in abstract "Term".


I've allready tried to move relationships "seminar" to abstract "Term", but I can't figure out how to define relations from "Seminar" entity to "Type" end "Section".


BTW, I'm using fetchedResultController in such way for UITableView cells/section/updates/notifications magic. I can filter results programmatically and fill controller model myself, but if there is any way to stay in core data paradigm it will be great.


In some moment Xcode get crazy and crashed until I've discarded all changes to the model.


My code is rather simple:


NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];

NSEntityDescription *entity = [NSEntityDescription entityForName:@"Term" inManagedObjectContext:self.managedObjectContext];
fetchRequest.entity = entity;

fetchRequest.fetchBatchSize = 20;

NSArray *sortDescriptors = @[[[NSSortDescriptor alloc] initWithKey:@"vid" ascending:NO],
[NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)]];

fetchRequest.sortDescriptors = sortDescriptors;

NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"vid" cacheName:CACHE_NAME];

Thanks for help.


0 commentaires:

Enregistrer un commentaire