Class: ActiveRecord::Associations::HasManyThroughAssociation

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

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#find(*args) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/eload_select.rb', line 18

def find(*args)
  options = Base.send(:extract_options_from_args!, args)

  conditions = "#{@finder_sql}"
  if sanitized_conditions = sanitize_sql(options[:conditions])
    conditions << " AND (#{sanitized_conditions})"
  end
  options[:conditions] = conditions

  if options[:order] && @reflection.options[:order]
    options[:order] = "#{options[:order]}, #{@reflection.options[:order]}"
  elsif @reflection.options[:order]
    options[:order] = @reflection.options[:order]
  end

  options[:from]  ||= construct_from
  options[:joins]   = construct_joins(options[:joins])
  options[:include] = @reflection.source_reflection.options[:include] if options[:include].nil?
  options[:select]||= @reflection.options[:select]||("#{@reflection.table_name}.*" unless options[:include])
  
  merge_options_from_reflection!(options)

  # Pass through args exactly as we received them.
  args << options
  @reflection.klass.find(*args)
end