我正在尝试查找除id为数组exclude_ids成员的用户以外的所有用户 这就是我所拥有的: User.where("id != ?", exclude_ids) 仅当exclude_ids只有1个元素时才有效.如果它有多个元素,我会得到 这个错误
这就是我所拥有的:
User.where("id != ?", exclude_ids)
仅当exclude_ids只有1个元素时才有效.如果它有多个元素,我会得到
这个错误:
ActiveRecord::StatementInvalid: SQLite3::SQLException: near ",": syntax error: SELECT "users".* FROM "users" WHERE (id != 1,2)
我很感激任何帮助.
我没有使用Rails 3,但使用User.where不安全(“id in#{exclude_ids}?”).在Rails 2.x上,您可以按如下方式执行此操作
User.find(:all, :conditions => ["id NOT IN (?)", [1,2,3]])
Rails 3.x docs http://railsapi.com/doc/rails-v3.0.0.beta.3/classes/ActiveRecord/Base.html