Module: Models::SearchableViewWithLineItems::ClassMethods
- Defined in:
- app/concerns/models/searchable_view_with_line_items.rb
Overview
ActiveSupport::Concern mixin: class methods.
Instance Method Summary collapse
-
#clean_array_params(params) ⇒ Array<Integer>
Normalizes scope arguments into a clean list of integer IDs.
-
#item_sql_check ⇒ String
SQL EXISTS fragment matching resources that have any of the given items among their line items.
-
#product_category_sql_check ⇒ String
Uses ltree for efficient descendant queries on items' denormalized paths.
-
#product_line_sql_check ⇒ String
Uses ltree for efficient descendant queries on items' denormalized paths.
-
#ransackable_scopes(_auth_object = nil) ⇒ Array<Symbol>
Extend the parent concern's ransackable_scopes with line-item scopes.
Instance Method Details
#clean_array_params(params) ⇒ Array<Integer>
Normalizes scope arguments into a clean list of integer IDs.
34 35 36 |
# File 'app/concerns/models/searchable_view_with_line_items.rb', line 34 def clean_array_params(params) [params].flatten.compact.uniq.map(&:to_i) end |
#item_sql_check ⇒ String
SQL EXISTS fragment matching resources that have any of the given items
among their line items.
60 61 62 63 64 65 66 67 68 69 |
# File 'app/concerns/models/searchable_view_with_line_items.rb', line 60 def item_sql_check %{ EXISTS (select 1 from line_items li where li.resource_id = #{table_name}.id and li.resource_type = '#{main_resource_class}' and li.item_id IN (?)) } end |
#product_category_sql_check ⇒ String
Uses ltree for efficient descendant queries on items' denormalized paths
76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/concerns/models/searchable_view_with_line_items.rb', line 76 def product_category_sql_check %{ EXISTS (select 1 from line_items li inner join items i on li.item_id = i.id where li.resource_id = #{table_name}.id and li.resource_type = '#{main_resource_class}' and i.pc_path_ids <@ ANY(SELECT ltree_path_ids FROM product_categories WHERE id = ANY(ARRAY[?]::integer[]))) } end |
#product_line_sql_check ⇒ String
Uses ltree for efficient descendant queries on items' denormalized paths
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/concerns/models/searchable_view_with_line_items.rb', line 43 def product_line_sql_check %{ EXISTS (select 1 from line_items li inner join items i on i.id = li.item_id where li.resource_id = #{table_name}.id and li.resource_type = '#{main_resource_class}' and (i.primary_pl_path_ids <@ ANY(SELECT ltree_path_ids FROM product_lines WHERE id = ANY(ARRAY[?]::integer[])) OR i.all_pl_paths_ids && ARRAY(SELECT ltree_path_ids FROM product_lines WHERE id = ANY(ARRAY[?]::integer[]))::ltree[])) } end |
#ransackable_scopes(_auth_object = nil) ⇒ Array<Symbol>
Extend the parent concern's ransackable_scopes with line-item scopes.
Must live in ClassMethods (not included do def self.) so that super
in the including model's own ransackable_scopes properly traverses here.
24 25 26 27 28 |
# File 'app/concerns/models/searchable_view_with_line_items.rb', line 24 def ransackable_scopes(_auth_object = nil) super + %i[contains_item_ids not_contains_item_ids contains_product_line_ids not_contains_product_line_ids contains_product_category_ids not_contains_product_category_ids] end |