Class: ActiveRecord::Associations::AssociationCollection

Inherits:
AssociationProxy show all
Defined in:
lib/active_record/connection_adapters/ibm_db_pstmt.rb

Overview

End of class HasManyAssociation

Instance Method Summary collapse

Methods inherited from AssociationProxy

#conditions

Instance Method Details

#find(*args) ⇒ Object



1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
# File 'lib/active_record/connection_adapters/ibm_db_pstmt.rb', line 1430

def find(*args)
  options = args.extract_options!

  param_array = []
  # If using a custom finder_sql, scan the entire collection.
  if @reflection.options[:finder_sql]
    expects_array = args.first.kind_of?(Array)
    ids           = args.flatten.compact.uniq.map { |arg| arg.to_i }

    if ids.size == 1
      id = ids.first
      record = load_target.detect { |r| id == r.id }
      expects_array ? [ record ] : record
    else
      load_target.select { |r| ids.include?(r.id) }
    end
  else
    conditions = "#{@finder_sql}"
    param_array = param_array + @finder_sql_param_array unless @finder_sql_param_array.nil?
    if sanitized_conditions = sanitize_sql(options[:conditions])
      conditions << " AND (#{sanitized_conditions["sqlSegment"]})"
      unless sanitized_conditions["paramArray"].nil?
        param_array = param_array + sanitized_conditions["paramArray"]
      end
    end

    if param_array.nil?
      options[:conditions] = conditions
    else
      options[:conditions] = [conditions] + param_array
    end

    if options[:order] && @reflection.options[:order]
      options[:order] = "#{options[:order]}, #{@reflection.options[:order]}"
    elsif @reflection.options[:order]
      options[:order] = @reflection.options[:order]
    end
    
    # Build options specific to association
    construct_find_options!(options)
    
    merge_options_from_reflection!(options)

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