0

查询所有者不是 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
4

2 回答 2

1

try using a separate where method call for each condition, these will generate sql AND

Something.where("owner_id <> ?", current_user.id)
  .where("recipient_id = ?", current_user.id)
  .where("owner_type = ?", "User")
于 2013-07-04T03:02:49.220 回答
1

我在评论中发布了一个解决方案,但您也可以执行类似的操作

.where("owner_id != #{current_user.id} AND recipient_id = #{current_user.id} AND owner_type = \"User\"")

于 2013-07-04T00:17:31.250 回答