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



1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
# File 'lib/active_record/connection_adapters/ibm_db_pstmt.rb', line 1369

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"]})"
      param_array << sanitized_conditions["paramArray"] unless sanitized_conditions["paramArray"].nil?
    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