Class: Babik::QuerySet::Condition::Conjunction
- Inherits:
-
Object
- Object
- Babik::QuerySet::Condition::Conjunction
- Defined in:
- lib/babik/queryset/lib/condition.rb
Overview
AND-based condition, also known as conjunction
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#selections ⇒ Object
readonly
Returns the value of attribute selections.
Instance Method Summary collapse
-
#initialize(model, filter) ⇒ Conjunction
constructor
Construct a conjunction condition.
-
#left_joins_by_alias ⇒ Hash
Return a hash with the joins grouped by alias.
-
#sql ⇒ String
Return SQL code for this conjunction.
Constructor Details
#initialize(model, filter) ⇒ Conjunction
Construct a conjunction condition.
30 31 32 33 34 35 36 37 |
# File 'lib/babik/queryset/lib/condition.rb', line 30 def initialize(model, filter) @model = model @selections = [] # filter is a Hash composed by :selection_path => value filter.each do |selection_path, value| @selections << Babik::Selection::Base.factory(@model, selection_path, value) end end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
25 26 27 |
# File 'lib/babik/queryset/lib/condition.rb', line 25 def model @model end |
#selections ⇒ Object (readonly)
Returns the value of attribute selections.
25 26 27 |
# File 'lib/babik/queryset/lib/condition.rb', line 25 def selections @selections end |
Instance Method Details
#left_joins_by_alias ⇒ Hash
Return a hash with the joins grouped by alias
41 42 43 44 45 46 47 |
# File 'lib/babik/queryset/lib/condition.rb', line 41 def left_joins_by_alias left_joins_by_alias_ = {} @selections.each do |selection| left_joins_by_alias_.merge!(selection.left_joins_by_alias) end left_joins_by_alias_ end |
#sql ⇒ String
Return SQL code for this conjunction. e.g
(first_name = 'Julius' AND last_name = 'Caesar' AND zone = 'Rome')
53 54 55 |
# File 'lib/babik/queryset/lib/condition.rb', line 53 def sql @selections.map(&:sql_where_condition).join(" AND\n") end |