diff options
Diffstat (limited to 'app/models/concerns/bulk_insert_safe.rb')
-rw-r--r-- | app/models/concerns/bulk_insert_safe.rb | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/app/models/concerns/bulk_insert_safe.rb b/app/models/concerns/bulk_insert_safe.rb index 908f0b6a7e2..6c3093ca916 100644 --- a/app/models/concerns/bulk_insert_safe.rb +++ b/app/models/concerns/bulk_insert_safe.rb @@ -51,6 +51,12 @@ module BulkInsertSafe PrimaryKeySetError = Class.new(StandardError) class_methods do + def insert_all_proxy_class + @insert_all_proxy_class ||= Class.new(self) do + attr_readonly :created_at + end + end + def set_callback(name, *args) unless _bulk_insert_callback_allowed?(name, args) raise MethodNotAllowedError, @@ -138,7 +144,7 @@ module BulkInsertSafe when nil false else - raise ArgumentError, "returns needs to be :ids or nil" + returns end # Handle insertions for tables with a composite primary key @@ -153,9 +159,9 @@ module BulkInsertSafe item_batch, validate, &handle_attributes) ActiveRecord::InsertAll - .new(self, attributes, on_duplicate: on_duplicate, returning: returning, unique_by: unique_by) + .new(insert_all_proxy_class, attributes, on_duplicate: on_duplicate, returning: returning, unique_by: unique_by) .execute - .pluck(primary_key) + .cast_values(insert_all_proxy_class.attribute_types).to_a end end end |