Skip to content

Commit

Permalink
if value doesn't respond to #empty? we don't want to continue
Browse files Browse the repository at this point in the history
  • Loading branch information
zmariscal committed Sep 26, 2023
1 parent 69aced2 commit c95dc75
Showing 1 changed file with 1 addition and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def insert(arel, name = nil, pk = nil, id_value = nil, sequence_name = nil, bind
value = exec_insert(sql, name, binds, pk, sequence_name)

return id_value if id_value
if pk.is_a?(Array) && !active_record_result(value).empty?
if pk.is_a?(Array) && value.respond_to?(:empty?) && !value.empty?
# This is a CPK model and the query result is not empty. Thus we can figure out the new ids for each
# auto incremented field
pk.map {|key| value.first[key]}
Expand All @@ -31,16 +31,6 @@ def insert(arel, name = nil, pk = nil, id_value = nil, sequence_name = nil, bind
last_inserted_id(value)
end
end

private

def active_record_result(value)
return value if @config[:adapter] != "trilogy"

# Create an AR Result so we can respond to #empty?
# since Trilogy:Result doesn't respond to it.
ActiveRecord::Result.new(value.fields, value.to_a)
end
end
end
end

0 comments on commit c95dc75

Please sign in to comment.