I’m trying to recreate a has_many :through relationship (like in Rails) with Objective-C, if Core Data is backed by SQLite, this must be possible right? <rant> I could write the raw SQL for this in 2 seconds… </rant>
Anyway, basically here is a sub-set of my schema: TutorGroup —-< Allocation >—- Category, what I need to get is all categories that are allocated to a particular tutor group.
Here is my query so far:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(SUBQUERY(Allocation, $row, $row.tutor_group == %@ AND $row.category == <CURRENT_ROW>).@count > 0)", tutor_group];
Is there a way to represent the current row’s object in a sub-query (where I’ve written <CURRENT_ROW> ? I’ve tried using self but that doesn’t work.
Also, I’m assuming where I’ve put Allocation is the table name I want to perform the sub query on?
Cheers.
I’m not sure it will work, but try this:
Then pass in your tutor group using predicateWithFormat, and run it on Category.