From ba795c9e4acc3954f52ad9f4d1059964a51cdce0 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Wed, 6 Mar 2019 16:19:53 +0100 Subject: Handle blank inserts like update_all; raise upfront. --- activerecord/lib/active_record/insert_all.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'activerecord/lib/active_record/insert_all.rb') diff --git a/activerecord/lib/active_record/insert_all.rb b/activerecord/lib/active_record/insert_all.rb index ca5ce11d79..6d14ff70b6 100644 --- a/activerecord/lib/active_record/insert_all.rb +++ b/activerecord/lib/active_record/insert_all.rb @@ -5,6 +5,8 @@ module ActiveRecord attr_reader :model, :connection, :inserts, :on_duplicate, :returning, :unique_by def initialize(model, inserts, on_duplicate:, returning: nil, unique_by: nil) + raise ArgumentError, "Empty list of attributes passed" if inserts.blank? + @model, @connection, @inserts, @on_duplicate, @returning, @unique_by = model, model.connection, inserts, on_duplicate, returning, unique_by @returning = (connection.supports_insert_returning? ? primary_keys : false) if @returning.nil? @returning = false if @returning == [] @@ -14,15 +16,11 @@ module ActiveRecord end def execute - if inserts.present? - connection.exec_query to_sql, "Bulk Insert" - else - ActiveRecord::Result.new([], []) - end + connection.exec_query to_sql, "Bulk Insert" end def keys - inserts.present? ? inserts.first.keys.map(&:to_s) : [] + inserts.first.keys.map(&:to_s) end def updatable_columns -- cgit v1.2.3