class Babik::QuerySet::Disjunction

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')

Attributes

conjunctions[R]
model[R]

Public Class Methods

new(model, conjunctions) click to toggle source

Construct a conjunction condition. @param model [ActiveRecord::Base] Model owner of this condition. @param conjunctions [Array] array of conjunctions that will be

joined in a disjunction (hence the name Disjunctive Normal Form).
# File lib/babik/queryset/lib/condition.rb, line 76
def initialize(model, conjunctions)
  @model = model
  @conjunctions = conjunctions
end

Public Instance Methods

left_joins_by_alias() click to toggle source

Return a hash with the joins grouped by alias @return [Hash] alias: SQL::Join object

# 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() click to toggle source

Return SQL code for this disjunction. e.g

(first_name = 'Julius' AND last_name = 'Caesar') OR (zone.name = 'Rome')

@return [String] SQL code that will be used in the WHERE part of SQL SELECT statements.

# File lib/babik/queryset/lib/condition.rb, line 95
def sql
  "(\n#{@conjunctions.map(&:sql).join(" OR\n")}\n)"
end