Class: Babik::QuerySet::Disjunction
- Inherits:
-
Object
- Object
- Babik::QuerySet::Disjunction
- Defined in:
- lib/babik/queryset/lib/condition.rb
Overview
Disjunction in Disjunctive Normal Form i.e OR-based condition of AND-based conditions (disjunction of conjunctions)
See en.wikipedia.org/wiki/Disjunctive_normal_form
e.g.
(users.filter_name = 'Julius' AND posts.title = 'Stabbed to death: My story') OR
(users.filter_name = 'Marcus Antonius' AND posts.title = 'A sword in my belly button')
Instance Attribute Summary collapse
-
#conjunctions ⇒ Object
readonly
Returns the value of attribute conjunctions.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
-
#initialize(model, conjunctions) ⇒ Disjunction
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 disjunction.
Constructor Details
#initialize(model, conjunctions) ⇒ Disjunction
Construct a conjunction condition.
76 77 78 79 |
# File 'lib/babik/queryset/lib/condition.rb', line 76 def initialize(model, conjunctions) @model = model @conjunctions = conjunctions end |
Instance Attribute Details
#conjunctions ⇒ Object (readonly)
Returns the value of attribute conjunctions.
70 71 72 |
# File 'lib/babik/queryset/lib/condition.rb', line 70 def conjunctions @conjunctions end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
70 71 72 |
# File 'lib/babik/queryset/lib/condition.rb', line 70 def model @model end |
Instance Method Details
#left_joins_by_alias ⇒ Hash
Return a hash with the joins grouped by alias
83 84 85 86 87 88 89 |
# File 'lib/babik/queryset/lib/condition.rb', line 83 def left_joins_by_alias left_joins_by_alias_ = {} @conjunctions.each do |conjunction| left_joins_by_alias_.merge!(conjunction.left_joins_by_alias) end left_joins_by_alias_ end |
#sql ⇒ String
Return SQL code for this disjunction. e.g
(first_name = 'Julius' AND last_name = 'Caesar') OR (zone.name = 'Rome')
95 96 97 |
# File 'lib/babik/queryset/lib/condition.rb', line 95 def sql "(\n#{@conjunctions.map(&:sql).join(" OR\n")}\n)" end |