Question

Here's the abstract situation: I have CoreData objects 'car' and 'review'.'review' can be 'good','bad' or 'meh', car->review is one-to-many.

I am trying to build an NSPredicate to get all 'car' objects with more than 3 'good' reviews.

In SQL I'd do something like:

SELECT car.name,COUNT(review.id) AS good_reviews 
  FROM car JOIN review ON (car.id=review.car_id)
  WHERE review.type='good'
  GROUP BY car.name
  HAVING good_reviews>3;

What's the predicate way of thinking about these kinds of selections?

'ANY' will let me match cars with at least 1 review of a given type, but what about more specific numbers?

Thanks for any help, and apologies if I've missed something obvious.

Peter

Was it helpful?

Solution

The answer I found was to set up a fetched property on the car object to get all the 'good' review objects. Counting that gave me the answer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top