重複を返す Rails スコープ クエリがあります。何が問題なのか誰にもわかりますか?コードは次のとおりです。
scope :visible_to_user, lambda { |user|
{
:joins => 'LEFT JOIN SCHEMA.groups ON groups.id = uploaded_files.group_id
LEFT JOIN uploaded_file_references ON uploaded_files.id = uploaded_file_references.uploaded_file_id
LEFT JOIN message_threads ON message_threads.id = uploaded_file_references.thread_id
LEFT JOIN thread_participants ON thread_participants.message_thread_id = message_threads.id',
:conditions => [
%{
uploaded_files.in_private_conversation = false
AND ( ( NOT COALESCE(groups.private, false) )
OR uploaded_files.group_id IN (?)
OR ( thread_participants.referenced_id = '?'
AND thread_participants.referenced_type = 'User')
)
}, user.group_ids, user.id
]
}
}