# models/micropost.rb
def self.from_users_followed_by(user)
followed_user_ids = "SELECT followed_id FROM relationships
WHERE follower_id = :user_id"
where("user_id IN (#{followed_user_ids}) OR
user_id = :user_id", user_id: user.id)
end
def self.in_reply_to(user)
where("content LIKE :user_login", user_login: '@' + user.login + '%')
end
# models/user.rb
def feed
Micropost.from_users_followed_by(self).in_reply_to(self) # AND
end
它有效,但我需要用户的微博,然后是用户 OR(不是 AND!)回复用户。