iphone - How to setup a predicate for this query -


I have a 3 object hierarchy in which the 'division' is original, in which many 'group' items and each ' Group 'has many employees.

division [1] ------ [*] group

group [1] ------ [*] employee

< / Blockquote>

I would like to know how to create an NSPredicate for the search of all employees of all groups of a specific division, the creation has been sorted by date / time and classified using their 'group' To know the 'Employee' object and specific division ID as the requested entity.

But I'm having trouble translating it into CoreData, so any suggestion would be helpful.

i was to create a SQL query, this would be something like this:

Select from employee * where - in exampleEdId (select * from group * g.divisionId =: DivisionId )

I tried to do this but did not work:

  // Create a fetch request for the institution. NSFetchRequest * fetchRequest = [[NSFetchRequest alloc] init]; // Configure the unit of the request and its definition NSEntityDescription * entity = [NSEntityDescription EntityForName: @ Managed object contexts in "employee": context]; [FetchRequest Set Entity: Entity]; // Create undoubtedly NSPredicate * predicate = [NSPredicate predicateWithFormat: @ "SELF.groups IN% @", [NSArray arrayWithArray: [[Employee groups] allObjects]]]; [FetchRequest set candidate: count]; // Edit the sort key as appropriate NSSortDescriptor * createDateSortDcptor = [[NSSortDescriptor alloc] initWithKey: @ "createDateTime" ascending: yes]; NSArray * sortDescriptors = [[NSArray alloc] initWithObjects: createDateSortDcptor, zero]; [Set FetchRequestSercript: Sort Descriptor];  

My object hierarchy is this:

  @ Interface Division: NSManage Object {} @ property (nontomic, write) NSDT * createDateTime; @property (nonatomic, retain) NSSet * groups; @end @text group: nsmainage object {} @property (nontomic, rETAIN) NSDT * create time; @property (nonatomic, intact) division * division; @property (nonatomic, retain) NSSet * employee; @ And @ interface staff: NSManagedObject {} @property (nonatomic, retain) NSDate * createDateTime; @property (nonatomic, retain) NSSet * groups; @end  

It looks like you want to make a predicate

NSPredicate * predicate = [NSPredicate predicateWithFormat: @ "Any SELF.groups IN% @", [Partitioning Groups]];

Where partition is a partition example. It will find all the employee examples which belong to the groups of any division.

Your code looks correct to correct the result.

If you expect such many employees, and you want to bring results in the batch, then your attitude is correct by using a fetch request. If you are expecting at least employees, you can also use key-valley coding:

  NSArray * divisionEmployees = [Partition values ​​forKeyPath: @ "@ unionOfSets. Groups.employees "];  

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -