【问题标题】:How to use an array in the condition as a filter - Ruby Rails如何在条件中使用数组作为过滤器 - Ruby Rails
【发布时间】:2012-04-12 03:19:33
【问题描述】:
array_users = ["3581", "3592", "3665", "3730"]

@records = Model.find(
           :all, 
           :order => 'date desc', 
           :group => :date, 
           :conditions => {
                 :client_id => current_user.client.id,  
                 :user_id is present in array_users # <------------------
           })

如何使用 Rails 2.3.9 确定只有返回的记录有 user_id 存在于 array_users 中?

【问题讨论】:

  • 您没有运行 v2.3.14 有什么原因吗?与 v2.3.9 之间有很多重要的安全修复。
  • 感谢您指出这一点。我不知道 .14。
  • 您绝对应该确保您使用某种方法来保持对新版本的更新,尤其是因为此时对 2.3 的任何更新都是重要的安全修复。

标签: ruby-on-rails ruby-on-rails-2


【解决方案1】:
:conditions => {
  :client_id => current_user.client.id,  
  :user_id => array_users
})

请参阅the guide 了解哈希条件的所有可能性。

【讨论】:

  • 谢谢。工作完美,并为参考指南。里面的东西很棒。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-14
  • 1970-01-01
  • 2021-09-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多