문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top