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

- (Associations) initialize(model)

Returns a new instance of 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

- (Object) model (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

- (Object) add_join_to(stack)



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

def add_join_to(stack)
  join_for(stack)
end

- (Boolean) aggregate_for?(stack)

Returns:

  • (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

- (Object) alias_for(stack)



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

- (Object) join_values



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

def join_values
  @joins.values.compact
end

- (Object) model_for(stack)



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