You want to use CollectionOperators.
NSLog(@"%@", [results valueForKeyPath:@"@distinctUnionOfObjects.students"]);
Question
I have two entities: Schedule
and User
. Schedule
has a relationship students
, which is many to one with User
(with an inverse of studentSchedule
).
I have all the required Schedule
objects in an array called results
, but I want to actually get the unique User
s from the students
relationship.
I am using:
NSLog(@"%@", [results valueForKeyPath:@"students"]);
But I am not getting the correct result as I think due to to Many relation. Does anyone have any idea about this?
Solution
You want to use CollectionOperators.
NSLog(@"%@", [results valueForKeyPath:@"@distinctUnionOfObjects.students"]);