Module: Shared::AlternateValues::ClassMethods
- Defined in:
- app/models/concerns/shared/alternate_values.rb
Instance Method Summary collapse
-
#with_alternate_value_on(a, b) ⇒ Scope
Use Source.with_alternate_value_on(:title, ‘foo’).
-
#with_any_value_for(attribute, value) ⇒ Scope
Use Source.with_any_value_for(:title, ‘foo’).
Instance Method Details
#with_alternate_value_on(a, b) ⇒ Scope
Use
Source.with_alternate_value_on(:title, 'foo')
42 43 44 |
# File 'app/models/concerns/shared/alternate_values.rb', line 42 def with_alternate_value_on(a, b) joins(:alternate_values).where(alternate_values: {alternate_value_object_attribute: a, value: b}) end |
#with_any_value_for(attribute, value) ⇒ Scope
Use
Source.with_any_value_for(:title, 'foo')
51 52 53 54 55 56 57 58 59 |
# File 'app/models/concerns/shared/alternate_values.rb', line 51 def with_any_value_for(attribute, value) self_table = self.arel_table alternate_value_table = AlternateValue.arel_table a = alternate_value_table[:value].eq(value).and(alternate_value_table[:alternate_value_object_attribute].eq(attribute)) b = self_table[attribute].eq(value) self.includes(:alternate_values).where(a.or(b).to_sql).references(:alternate_values) end |