Created
August 21, 2013 15:54
-
-
Save ys/6296323 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SuggestedUsers | |
attr_reader :user | |
def initialize(user) | |
@user = user | |
end | |
def suggested_users | |
User.joins('JOIN follows as follows_follows ON follows_follows.followee_id = users.id') | |
.joins('JOIN follows as user_follows ON follows_follows.follower_id = user_follows.followee_id') | |
.where('follows_follows.followee_id NOT IN (SELECT followee_id FROM follows WHERE follower_id = :user_id)', user_id: user.id) | |
.where('user_follows.follower_id = :user_id', user_id: user.id) | |
end | |
alias_method :all, :suggested_users | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment