Module: Queries::Concerns::AlternateValues

Extended by:
ActiveSupport::Concern
Included in:
Person::Autocomplete, Repository::Autocomplete
Defined in:
lib/queries/concerns/alternate_values.rb

Overview

Helpers for queries that reference AlternateValue

!! Classes including this must be subclasses of Queries::Query !!

Instance Method Summary collapse

Instance Method Details

#matching_alternate_value_on(attribute = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/queries/concerns/alternate_values.rb', line 19

def matching_alternate_value_on(attribute = nil)
  return nil if attribute.nil?  # empty? keyword_ids.empty?
  k = table.name.classify.safe_constantize
  t = ::AlternateValue.arel_table

  k.joins(:alternate_values).where(
    t[:value].matches_any(terms) # terms is from Queries::Query
    .and( t[:alternate_value_object_attribute].eq(attribute)) # terms is from Queries::Query
    .and(t[:type].eq_any(alternate_value_type))
    .to_sql
  )
end

#matching_alternate_value_on_values(attribute = nil, values = []) ⇒ Object

TODO: not used, but potentially useful



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/queries/concerns/alternate_values.rb', line 33

def matching_alternate_value_on_values(attribute = nil, values = [])
  return nil if attribute.nil? || values.compact.empty?
  k = table.name.classify.safe_constantize
  t = ::AlternateValue.arel_table

  k.joins(:alternate_values).where(
    t[:value].matches_any(values) # terms is from Queries::Query
    .and( t[:alternate_value_object_attribute].eq(attribute)) # terms is from Queries::Query
    .and(t[:type].eq_any(alternate_value_type))
    .to_sql
  )
end

#set_alternate_value(params) ⇒ Object



15
16
17
# File 'lib/queries/concerns/alternate_values.rb', line 15

def set_alternate_value(params)
  @alternate_value_type = params[:alternate_value_type] || ALTERNATE_VALUE_CLASS_NAMES
end