두 개 모두 Micropost 모델 내부에 관계를 반환하는 코드가 있습니다.OR 대신에 AND 관계를 AND
scope :including_replies, lambda { |user| where("microposts.in_reply_to = ?", user.id)}
def self.from_users_followed_by(user)
followed_user_ids = user.followed_user_ids
where("user_id IN (?) OR user_id = ?", followed_user_ids, user)
end
내가 r1 = Micropost.including_replies(user)
를 실행하면 내가받을 다음과 같은 SQL 두 결과와의 관계 :
SELECT `microposts`.* FROM `microposts` WHERE (microposts.in_reply_to = 102) ORDER BY
microposts.created_at DESC
내가 r2 = Micropost.from_users_followed_by(user)
을 실행할 때 나는 다음과 같은 SQL 한 결과에 관계 얻을 :
SELECT `microposts`.* FROM `microposts` WHERE (user_id IN (NULL) OR user_id = 102) ORDER
BY microposts.created_at DESC
을
이제는 관계를 병합 할 때 r3 = r1.merge(r2)
결과가 0이되었지만 3을 기대하고있었습니다. 그 이유는 SQL은 다음과 같습니다이다 :
SELECT `microposts`.* FROM `microposts` WHERE (microposts.in_reply_to = 102) AND
(user_id IN (NULL) OR user_id = 102) ORDER BY microposts.created_at DESC
은 이제 필요
(microposts.in_reply_to = 102) OR (user_id IN (NULL) OR user_id = 102)
입니다 내가
OR
대신 병합 관계에
AND
이 필요합니다.
이 방법이 있습니까?