class Babik::QuerySet::Condition::Conjunction
AND-based condition, also known as conjunction
Attributes
model[R]
selections[R]
Public Class Methods
new(model, filter)
click to toggle source
Construct a conjunction condition. @param model [ActiveRecord::Base] Model owner of this condition. @param filter [Hash] a hash where the key identify field paths and the values the values they must take.
# 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
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 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()
click to toggle source
Return SQL code for this conjunction. e.g
(first_name = 'Julius' AND last_name = 'Caesar' AND zone = '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 53 def sql @selections.map(&:sql_where_condition).join(" AND\n") end