默认作用域,自动加载:

default_scope { order(created_at: :desc) }

 

model 调用 find_2时才运行

scope :find_2, ->{ where('clients.id' => 2 ) }

 

下面都需要传参,使用model.find_2(id)调用

scope :find_2, ->(id) { where('clients.id' => id) }

scope :find_2, lambda { |id| where('clients.id' => id) }

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-02-06
  • 2021-08-22
  • 2022-12-23
  • 2021-10-12
  • 2022-12-23
  • 2021-07-17
猜你喜欢
  • 2021-06-23
  • 2021-08-13
  • 2022-12-23
  • 2022-12-23
  • 2021-11-29
  • 2022-01-29
  • 2022-12-23
相关资源
相似解决方案