Skip to content

Commit ebc8498

Browse files
committed
refactor: read touch_update_defaults? from options instead of changeset context
Read the touch_update_defaults? flag from the bulk_create options map rather than from changeset context. Depends on ash-project/ash#2590 which adds touch_update_defaults? to the options passed to data layers. Only merge once that PR is merged and released.
1 parent 06a0680 commit ebc8498

2 files changed

Lines changed: 3 additions & 4 deletions

File tree

lib/data_layer.ex

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2382,9 +2382,8 @@ defmodule AshPostgres.DataLayer do
23822382
# Include fields with update_defaults (e.g. update_timestamp)
23832383
# even if they aren't in the changeset attributes or upsert_fields.
23842384
# These fields should always be refreshed when an upsert modifies fields.
2385-
# Can be disabled via context: %{data_layer: %{touch_update_defaults?: false}}
2386-
touch_update_defaults? =
2387-
Enum.at(changesets, 0).context[:data_layer][:touch_update_defaults?] != false
2385+
# Can be disabled via touch_update_defaults?: false option
2386+
touch_update_defaults? = Map.get(options, :touch_update_defaults?, true)
23882387

23892388
if touch_update_defaults? do
23902389
update_default_fields =

test/bulk_create_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ defmodule AshPostgres.BulkCreateTest do
224224
upsert?: true,
225225
upsert_identity: :uniq_one_and_two,
226226
upsert_fields: [:price],
227-
context: %{data_layer: %{touch_update_defaults?: false}},
227+
touch_update_defaults?: false,
228228
return_stream?: true,
229229
return_errors?: true,
230230
return_records?: true

0 commit comments

Comments
 (0)