7
我有一个Rails的ActiveRecord where
,看起来像这样:有没有可能不重复Rails的ActiveRecord条件参数?
Things.where('blahs.foo_id = ? OR bar_id = ?', user.id, user.id)
我想user.id
到位两个?
的使用。有没有办法像我所做的那样不重复它?
我有一个Rails的ActiveRecord where
,看起来像这样:有没有可能不重复Rails的ActiveRecord条件参数?
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)
非常优雅!我确定它存在! –