For the situation where Employee has_many Clients, I am trying to write an ActiveRecord query that will return all of the Employees that have n or more clients. It’s simple enough to write a join query to find all of the Employees with at least 1 client but extending my query to this more general case has left me stumped.
Edit – I should add that I’m trying to do this entirely at the database level. I want to avoid iterating over the collection in Ruby.
Thanks to mu and vijikumar, this is what I’ve come up with