查询所有者不是current_user的正确语法是什么:
.where(owner_id: != current_user.id, recipient_id: current_user.id, owner_type: "User")
我试过了:
where(['current_user.id <> ?', :owner_id ], recipient_id: current_user.id, owner_type: "User")
得到了:
undefined method `%' for ["current_user.id <> ?", :owner_id]:Array
答案 0 :(得分:1)
我在评论中发布了一个解决方案,但您也可以执行类似
的操作 .where("owner_id != #{current_user.id} AND recipient_id = #{current_user.id} AND owner_type = \"User\"")
答案 1 :(得分:1)
尝试对每个条件使用单独的where
方法调用,这些将生成sql AND
Something.where("owner_id <> ?", current_user.id)
.where("recipient_id = ?", current_user.id)
.where("owner_type = ?", "User")