I have the following:
Groups: id, title
GroupMembers: id, group_id, name
Groups have many group_members
How can I query the db to get all Groups which have at least 2 GroupMembers?
Try this:
Group.joins("(
SELECT group_id
FROM group_members
GROUP BY group_id
HAVING COUNT(1) > 1
) a ON a.member_id = groups.id")