Frage

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?

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top