2

I have a model with a has_many relationship to widgets and I'm trying to retrieve a unique list of users who have widgets (some have more than 1 widget).

User
 has_many :widgets

## join the user table 
User.joins{widgets}.where{ widgets.kind.eq 'widget_type' }.uniq

The problem is that #uniq does not appear to retrieve a unique set of user records.

I can perform

 User.joins{widgets}.where{ widgets.kind.eq 'widget_type' }.pluck("users.id").uniq 

To retrieve a unique set of user ids but there must be a may to find only the unique Users that fit this query?

Paul
  • 2,021
  • 5
  • 22
  • 33

0 Answers0