Class: ThinkingSphinx::ActiveRecord::Associations

Inherits:
Object
  • Object
show all
Defined in:
lib/thinking_sphinx/active_record/associations.rb

Constant Summary

JoinDependency =
::ActiveRecord::Associations::JoinDependency

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ Associations



6
7
8
9
# File 'lib/thinking_sphinx/active_record/associations.rb', line 6

def initialize(model)
  @model = model
  @joins = ActiveSupport::OrderedHash.new
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model



4
5
6
# File 'lib/thinking_sphinx/active_record/associations.rb', line 4

def model
  @model
end

Instance Method Details

#add_join_to(stack) ⇒ Object



11
12
13
# File 'lib/thinking_sphinx/active_record/associations.rb', line 11

def add_join_to(stack)
  join_for(stack)
end

#aggregate_for?(stack) ⇒ Boolean



15
16
17
18
19
20
21
22
23
# File 'lib/thinking_sphinx/active_record/associations.rb', line 15

def aggregate_for?(stack)
  return false if stack.empty?

  joins_for(stack).compact.any? { |join|
    [:has_many, :has_and_belongs_to_many].include?(
      join.reflection.macro
    )
  }
end

#alias_for(stack) ⇒ Object



25
26
27
28
29
# File 'lib/thinking_sphinx/active_record/associations.rb', line 25

def alias_for(stack)
  return model.quoted_table_name if stack.empty?

  join_for(stack).aliased_table_name
end

#join_valuesObject



31
32
33
# File 'lib/thinking_sphinx/active_record/associations.rb', line 31

def join_values
  @joins.values.compact
end

#model_for(stack) ⇒ Object



35
36
37
38
39
40
# File 'lib/thinking_sphinx/active_record/associations.rb', line 35

def model_for(stack)
  return model if stack.empty?

  join = join_for(stack)
  join.nil? ? nil : join.reflection.klass
end