class Babik::Selection::LocalSelection

Selection by a local field

Attributes

model[R]
operator[R]
secondary_operator[R]
selected_field[R]
selection_path[R]
value[R]

Public Class Methods

new(model, selection_path, value) click to toggle source

Construct a local field selector @param model [ActiveRecord::Base] model whose field will be used. @param selection_path [String] selection path. Of the form <field>__<operator>. e.g. first_name__equal, stars__gt

If no operator is given (first_name), 'equal' will be used.

@param value [String,Integer,Float,ActiveRecord::Base,Babik::QuerySet::Base] anything that can be used

to select objects.
Calls superclass method Babik::Selection::Path::LocalPath::new
# File lib/babik/queryset/lib/selection/local_selection.rb, line 20
def initialize(model, selection_path, value)
  super(model, selection_path)
  @value = value
end

Public Instance Methods

sql_where_condition() click to toggle source

Return the SQL where condition @return [Babik::Selection::Operation::Base] Condition obtained from the selection path and value.

# File lib/babik/queryset/lib/selection/local_selection.rb, line 27
def sql_where_condition
  actual_field = Babik::Table::Field.new(model, @selected_field).real_field
  # Return the condition
  operator = if @secondary_operator
               [@operator, @secondary_operator]
             else
               @operator
             end
  Babik::Selection::Operation::Base.factory("#{self.target_alias}.#{actual_field}", operator, @value)
end