Class: ActiveRecord::Associations::HasManyThroughAssociation

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

Instance Method Summary collapse

Instance Method Details

#find(*args) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/select_with_include/has_many_through_association.rb', line 4

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[:select]  = construct_select(options[:select], options[:include])
  options[:from]  ||= construct_from
  options[:joins]   = construct_joins(options[:joins])
  options[:include] = @reflection.source_reflection.options[:include] if options[:include].nil?

  merge_options_from_reflection!(options)

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