【问题标题】:Filterrific and Multitenancy, Limiting Active Record Results过滤和多租户,限制 Active Record 结果
【发布时间】:2016-05-25 21:28:31
【问题描述】:

我试图将过滤搜索的结果限制为仅具有给定 client_id 的实例。

我的设置如下:

# customers_controller.rb
@filterrific = initialize_filterrific(
    Customer,
    params[:filterrific],
    select_options: {
      sorted_by: Customer.options_for_sorted_by,
      with_agent_id: Agent.options_for_select
    },
  ) or return

有没有办法限制返回的活动记录结果,比如 Customer.where('client_id', 2) ?

【问题讨论】:

    标签: ruby-on-rails activerecord rails-activerecord filterrific


    【解决方案1】:

    你可以这样做:

    @filterrific = initialize_filterrific(
        Customer,
        params[:filterrific],
        select_options: {
          sorted_by: Customer.options_for_sorted_by,
          with_agent_id: Agent.options_for_select
        },
      ) or return
           @customers = @filterrific.find.where(client_id: 2).paginate(:page => params[:page], :per_page => 10) # add paginate if you require pagination
    

    【讨论】:

    • 感谢您的快速回答!还没有发现.find 返回活动记录。虽然回想起来这是有道理的,因为有人在上面分页。
    【解决方案2】:

    我想我真的想通了。看起来您只是将 FIND 传递给 @filterrific 定义...

    @appointments = @filterrific.find.where(vendor_id: @vendor_locations.select(:vendor_id))
    .page(params[:page])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-19
      • 1970-01-01
      相关资源
      最近更新 更多