Module: Models::SearchableViewWithLineItems::ClassMethods
- Defined in:
- app/concerns/models/searchable_view_with_line_items.rb
Instance Method Summary collapse
- #clean_array_params(params) ⇒ Object
- #item_sql_check ⇒ Object
-
#product_category_sql_check ⇒ Object
Uses ltree for efficient descendant queries on items' denormalized paths.
-
#product_line_sql_check ⇒ Object
Uses ltree for efficient descendant queries on items' denormalized paths.
-
#ransackable_scopes(_auth_object = nil) ⇒ Object
Extend the parent concern's ransackable_scopes with line-item scopes.
Instance Method Details
#clean_array_params(params) ⇒ Object
18 19 20 |
# File 'app/concerns/models/searchable_view_with_line_items.rb', line 18 def clean_array_params(params) [params].flatten.compact.uniq.map(&:to_i) end |
#item_sql_check ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'app/concerns/models/searchable_view_with_line_items.rb', line 36 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 ⇒ Object
Uses ltree for efficient descendant queries on items' denormalized paths
48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/concerns/models/searchable_view_with_line_items.rb', line 48 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 ⇒ Object
Uses ltree for efficient descendant queries on items' denormalized paths
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/concerns/models/searchable_view_with_line_items.rb', line 23 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) ⇒ Object
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.
12 13 14 15 16 |
# File 'app/concerns/models/searchable_view_with_line_items.rb', line 12 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 |