I have the following query which I would like to know how to execute in Rails 5
SELECT users.id, users.first_name, users.last_name, users.image, users.email, memberships.staff
FROM users
LEFT JOIN memberships
ON memberships.shop_id = 1
WHERE memberships.staff = false
I'd like a model method e.g.
Shop.staff
I've had no success with using .joins()
The join table has
user_id | shop_id | staff
1 | 2 | false
2 | 2 | true
In my Shop model I have:
has_and_belongs_to_many :users, join_table: "memberships"
I don't want to change this particular relationship since I don't require the join table as a model however I do want to filter users by using the staff column in the join table (true or false)
Ideally all the users that are staff should return when I call Shop.staff