我有一个看起来像这样的Rails ActiveRecord where
:
Things.where('blahs.foo_id = ? OR bar_id = ?', user.id, user.id)
我希望使用
user.id
代替两个?
。有没有办法像我一样不重复?
最佳答案
是的,仅使用哈希而不是重复变量。
Things.where('blahs.foo_id = :user_id OR bar_id = :user_id', :user_id => user.id)
关于ruby-on-rails - 是否可以在条件参数中不重复Rails ActiveRecord?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18456704/