Question

I have this active record query:

current_user.company.properties.pluck(:name).uniq

what I would like to do is get this query but only for properties with 'name' that occur at least twice. how would i do that?

Was it helpful?

Solution

You can group by name and add a having call as well:

...properties.group(:name).having("count(name) > 1").pluck(:name)

There's no longer any need for the uniq call because, as you're grouping by name, you'll only get each name returned once.

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