Codify import results in a Struct rather than OpenStruct, as it's a faster, more rigid structure
This commit is contained in:
parent
876546c584
commit
35786fef17
|
@ -3,6 +3,9 @@ require "ostruct"
|
||||||
module ActiveRecord::Import::ConnectionAdapters ; end
|
module ActiveRecord::Import::ConnectionAdapters ; end
|
||||||
|
|
||||||
module ActiveRecord::Import #:nodoc:
|
module ActiveRecord::Import #:nodoc:
|
||||||
|
class Result < Struct.new(:failed_instances, :num_inserts)
|
||||||
|
end
|
||||||
|
|
||||||
module ImportSupport #:nodoc:
|
module ImportSupport #:nodoc:
|
||||||
def supports_import? #:nodoc:
|
def supports_import? #:nodoc:
|
||||||
true
|
true
|
||||||
|
@ -200,7 +203,7 @@ class ActiveRecord::Base
|
||||||
import_with_validations( column_names, array_of_attributes, options )
|
import_with_validations( column_names, array_of_attributes, options )
|
||||||
else
|
else
|
||||||
num_inserts = import_without_validations_or_callbacks( column_names, array_of_attributes, options )
|
num_inserts = import_without_validations_or_callbacks( column_names, array_of_attributes, options )
|
||||||
OpenStruct.new :failed_instances=>[], :num_inserts=>num_inserts
|
ActiveRecord::Import::Result.new([], num_inserts)
|
||||||
end
|
end
|
||||||
|
|
||||||
if options[:synchronize]
|
if options[:synchronize]
|
||||||
|
@ -240,7 +243,7 @@ class ActiveRecord::Base
|
||||||
array_of_attributes.compact!
|
array_of_attributes.compact!
|
||||||
|
|
||||||
num_inserts = array_of_attributes.empty? ? 0 : import_without_validations_or_callbacks( column_names, array_of_attributes, options )
|
num_inserts = array_of_attributes.empty? ? 0 : import_without_validations_or_callbacks( column_names, array_of_attributes, options )
|
||||||
OpenStruct.new :failed_instances=>failed_instances, :num_inserts => num_inserts
|
ActiveRecord::Import::Result.new(failed_instances, num_inserts)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Imports the passed in +column_names+ and +array_of_attributes+
|
# Imports the passed in +column_names+ and +array_of_attributes+
|
||||||
|
|
Loading…
Reference in a new issue