I\'m querying for the mutual friends of a given two users. The query below should do the trick for the most part and the friendship table should be self-evident, containing
I do it with string arguments to joins:
joins
User. joins("INNER JOIN friendships a ON users.id = a.friend_id"). joins("INNER JOIN friendships b ON users.id = b.friend_id"). where("a.user_id" => 1, "b.user_id" => 2)
I'm not aware of a higher-level way to do such a join with Active Record.