@@ -355,6 +355,7 @@ def import_with_validations( column_names, array_of_attributes, options={} )
355355 instance = new do |model |
356356 hsh . each_pair { |k , v | model . send ( "#{ k } =" , v ) }
357357 end
358+
358359 if not instance . valid? ( options [ :validate_with_context ] )
359360 array_of_attributes [ i ] = nil
360361 failed_instances << instance
@@ -428,9 +429,14 @@ def import_without_validations_or_callbacks( column_names, array_of_attributes,
428429 def set_ids_and_mark_clean ( models , import_result )
429430 unless models . nil?
430431 import_result . ids . each_with_index do |id , index |
431- models [ index ] . id = id . to_i
432- models [ index ] . instance_variable_get ( :@changed_attributes ) . clear # mark the model as saved
433- models [ index ] . instance_variable_set ( :@new_record , false )
432+ model = models [ index ]
433+ model . id = id . to_i
434+ if model . respond_to? ( :clear_changes_information ) # Rails 4.0 and higher
435+ model . clear_changes_information
436+ else # Rails 3.1
437+ model . instance_variable_get ( :@changed_attributes ) . clear
438+ end
439+ model . instance_variable_set ( :@new_record , false )
434440 end
435441 end
436442 end
@@ -485,10 +491,12 @@ def values_sql_for_columns_and_attributes(columns, array_of_attributes) # :nod
485491 if val . nil? && column . name == primary_key && !sequence_name . blank?
486492 connection_memo . next_value_for_sequence ( sequence_name )
487493 elsif column
488- if column . respond_to? ( :type_cast_from_user ) # Rails 4.2 and higher
494+ if respond_to? ( :type_caster ) && type_caster . respond_to? ( :type_cast_for_database ) # Rails 5.0 and higher
495+ connection_memo . quote ( type_caster . type_cast_for_database ( column . name , val ) )
496+ elsif column . respond_to? ( :type_cast_from_user ) # Rails 4.2 and higher
489497 connection_memo . quote ( column . type_cast_from_user ( val ) , column )
490- else
491- connection_memo . quote ( column . type_cast ( val ) , column ) # Rails 3.1, 3.2, and 4.1
498+ else # Rails 3.1, 3.2, and 4.1
499+ connection_memo . quote ( column . type_cast ( val ) , column )
492500 end
493501 end
494502 end
@@ -499,7 +507,7 @@ def values_sql_for_columns_and_attributes(columns, array_of_attributes) # :nod
499507 def add_special_rails_stamps ( column_names , array_of_attributes , options )
500508 AREXT_RAILS_COLUMNS [ :create ] . each_pair do |key , blk |
501509 if self . column_names . include? ( key )
502- value = connection . quote blk . call
510+ value = blk . call
503511 if index = column_names . index ( key ) || index = column_names . index ( key . to_sym )
504512 # replace every instance of the array of attributes with our value
505513 array_of_attributes . each { |arr | arr [ index ] = value if arr [ index ] . nil? }
@@ -512,7 +520,7 @@ def add_special_rails_stamps( column_names, array_of_attributes, options )
512520
513521 AREXT_RAILS_COLUMNS [ :update ] . each_pair do |key , blk |
514522 if self . column_names . include? ( key )
515- value = connection . quote blk . call
523+ value = blk . call
516524 if index = column_names . index ( key ) || index = column_names . index ( key . to_sym )
517525 # replace every instance of the array of attributes with our value
518526 array_of_attributes . each { |arr | arr [ index ] = value }
0 commit comments