Reputation: 1584
For one nested relationship I would do this:
NSMutableArray *allClusters = [NSMutableArray arrayWithArray:[form.clusters allObjects]];
But what should I do for? :
NSMutableArray *allQuestions = [NSMutableArray arrayWithArray:[form.clusters.questions allObjects]];
Both clusters and questions are one-to-many relationships.
Any help is welcome
Upvotes: 1
Views: 434
Reputation: 1685
NSSet *allQuestionsOfForm = [form valueForKeyPath:@"clusters.questions"];
EDIT:
The code above returns a nested set as glorifiedHacker said. To get a flattened set use:
NSSet *allQuestionsOfForm = [form valueForKeyPath:@"[email protected]"];
Upvotes: 2
Reputation: 6420
It looks like you're dealing with nested sets, so you probably just need to iterate through the parent sets to collect the items in the child sets:
NSMutableArray *allQuestions = [NSMutableArray array];
for(Cluster *cluster in form.clusters) {
[allQuestions addObjectsFromArray:[cluster.questions allObjects]];
}
If this isn't what you're after, then you'll need to add some more detail to your original question.
Upvotes: 1