【发布时间】:2011-05-11 14:41:21
【问题描述】:
我正在使用“where”语法编写 Rails 3 ActiveRecord 查询,它同时使用 SQL IN 和 SQL OR 运算符,但不知道如何将它们一起使用。
此代码有效(在我的用户模型中):
Question.where(:user_id => self.friends.ids)
#note: self.friends.ids returns an array of integers
但是这段代码
Question.where(:user_id => self.friends.ids OR :target => self.friends.usernames)
返回此错误
syntax error, unexpected tCONSTANT, expecting ')'
...user_id => self.friends.ids OR :target => self.friends.usern...
知道如何在 Rails 中编写它,或者只是原始 SQL 查询应该是什么?
【问题讨论】:
标签: sql ruby-on-rails ruby ruby-on-rails-3 activerecord