Skip to content

Commit

Permalink
Use dataset to fetch record after insert
Browse files Browse the repository at this point in the history
Similarily to what Update command do, use `dataset` to load the tuple
after `insert` in Create command. This way it loads "raw" data, without
applying read types yet. So when tuples are passed into `finalize` hook,
it can properly apply these read types.
  • Loading branch information
katafrakt committed Oct 27, 2024
1 parent 52bd555 commit c4fc450
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/rom/sql/commands/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ def finalize(tuples, *)
# @api private
def insert(tuples)
pks = tuples.map { |tuple| relation.insert(tuple) }
relation.where(relation.primary_key => pks).to_a
relation.dataset.where(relation.primary_key => pks).to_a
end

# Executes multi_insert statement and returns inserted tuples
#
# @api private
def multi_insert(tuples)
pks = relation.multi_insert(tuples, return: :primary_key)
relation.where(relation.primary_key => pks).to_a
relation.dataset.where(relation.primary_key => pks).to_a
end

# Yields tuples for insertion or return an enumerator
Expand Down

0 comments on commit c4fc450

Please sign in to comment.