Class: RailsSimpleSearch::SqlHandler::SelectionItem

Inherits:
Object
  • Object
show all
Defined in:
lib/selection_item.rb

Overview

this class represents a single select statement, without unions or intersects.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, model_class, field, value) ⇒ SelectionItem

Returns a new instance of SelectionItem.



8
9
10
11
12
13
14
15
# File 'lib/selection_item.rb', line 8

def initialize(config, model_class, field, value)
  @config = config
  @model_class = model_class
  @field = field
  @value = value
  @joins = {}
  @verb = ''
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



6
7
8
# File 'lib/selection_item.rb', line 6

def field
  @field
end

#valueObject (readonly)

Returns the value of attribute value.



6
7
8
# File 'lib/selection_item.rb', line 6

def value
  @value
end

Instance Method Details

#to_sqlObject



17
18
19
20
21
22
23
24
# File 'lib/selection_item.rb', line 17

def to_sql
  build_select_with_condition(@field, @value)
  join_str = make_joins
  query = @model_class.joins(join_str)
  query = query.where(to_ar_condition)
  query = query.select("distinct #{@model_class.table_name}.*")
  query.to_sql
end