Class: ThinkingSphinx::ActiveRecord::Associations
- Inherits:
-
Object
- Object
- ThinkingSphinx::ActiveRecord::Associations
- Defined in:
- lib/thinking_sphinx/active_record/associations.rb
Constant Summary collapse
- JoinDependency =
::ActiveRecord::Associations::JoinDependency
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
- #add_join_to(stack) ⇒ Object
- #aggregate_for?(stack) ⇒ Boolean
- #alias_for(stack) ⇒ Object
-
#initialize(model) ⇒ Associations
constructor
A new instance of Associations.
- #join_values ⇒ Object
- #model_for(stack) ⇒ Object
Constructor Details
#initialize(model) ⇒ Associations
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
#model ⇒ Object (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_values ⇒ Object
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 |