Module: ProductGroupSearch::Extension

Defined in:
lib/nimbleshop/product_group_search/extension.rb

Instance Method Summary collapse

Instance Method Details

#searchObject

This module bring search feature to product_group. This is how it is used in product_group .

class ProductGroup
  has_many :product_group_conditions, dependent: :destroy, extend: ProductGroupSearch::Extension
  def products
    product_group_conditions.search
  end
end

12
13
14
# File 'lib/nimbleshop/product_group_search/extension.rb', line 12

def search
  Product.find_by_sql(to_search_sql)
end

#to_search_sqlObject


16
17
18
19
20
21
22
23
24
25
# File 'lib/nimbleshop/product_group_search/extension.rb', line 16

def to_search_sql
  set_indexes # custom_field_strategy needs it

  search_proxy = handle_joins
  search_proxy = search_proxy.where(handle_where_conditions)
  search_proxy = filter_on_active(search_proxy)
  search_proxy = search_proxy.project(Arel.sql("products.*"))

  search_proxy.to_sql
end