mirror of
https://github.com/ash-project/ash.git
synced 2024-09-19 13:03:02 +12:00
fix: fix upsert condition for ets bulk creates
This commit is contained in:
parent
de0f72b475
commit
3c90063c40
2 changed files with 24 additions and 12 deletions
|
@ -1019,10 +1019,20 @@ defmodule Ash.DataLayer.Ets do
|
||||||
conflicting_upsert_values \\ nil
|
conflicting_upsert_values \\ nil
|
||||||
)
|
)
|
||||||
|
|
||||||
|
defp filter_matches([], _, _domain, _tenant, _parent, _conflicting_upsert_values),
|
||||||
|
do: {:ok, []}
|
||||||
|
|
||||||
defp filter_matches(records, nil, _domain, _tenant, _parent, _conflicting_upsert_values),
|
defp filter_matches(records, nil, _domain, _tenant, _parent, _conflicting_upsert_values),
|
||||||
do: {:ok, records}
|
do: {:ok, records}
|
||||||
|
|
||||||
defp filter_matches(records, filter, domain, tenant, parent, conflicting_upsert_values) do
|
defp filter_matches(
|
||||||
|
records,
|
||||||
|
filter,
|
||||||
|
domain,
|
||||||
|
tenant,
|
||||||
|
parent,
|
||||||
|
conflicting_upsert_values
|
||||||
|
) do
|
||||||
Ash.Filter.Runtime.filter_matches(domain, records, filter,
|
Ash.Filter.Runtime.filter_matches(domain, records, filter,
|
||||||
parent: parent,
|
parent: parent,
|
||||||
tenant: tenant,
|
tenant: tenant,
|
||||||
|
@ -1075,8 +1085,7 @@ defmodule Ash.DataLayer.Ets do
|
||||||
upsert_conflict_check(
|
upsert_conflict_check(
|
||||||
changeset,
|
changeset,
|
||||||
result,
|
result,
|
||||||
conflicting_upsert_values,
|
conflicting_upsert_values
|
||||||
opts[:upsert_condition]
|
|
||||||
) do
|
) do
|
||||||
changeset =
|
changeset =
|
||||||
changeset
|
changeset
|
||||||
|
@ -1086,7 +1095,7 @@ defmodule Ash.DataLayer.Ets do
|
||||||
|
|
||||||
update(
|
update(
|
||||||
resource,
|
resource,
|
||||||
%{changeset | action_type: :update},
|
%{changeset | action_type: :update, filter: nil},
|
||||||
Map.take(result, pkey),
|
Map.take(result, pkey),
|
||||||
opts[:from_bulk_create?]
|
opts[:from_bulk_create?]
|
||||||
)
|
)
|
||||||
|
@ -1107,29 +1116,26 @@ defmodule Ash.DataLayer.Ets do
|
||||||
@spec upsert_conflict_check(
|
@spec upsert_conflict_check(
|
||||||
changeset :: Ash.Changeset.t(),
|
changeset :: Ash.Changeset.t(),
|
||||||
subject :: record,
|
subject :: record,
|
||||||
conflicting_upsert_values :: record,
|
conflicting_upsert_values :: record
|
||||||
opts_upsert_condition :: Ash.Expr.t()
|
|
||||||
) :: {:ok, [record]} | {:error, reason}
|
) :: {:ok, [record]} | {:error, reason}
|
||||||
when record: Ash.Resource.record(), reason: term()
|
when record: Ash.Resource.record(), reason: term()
|
||||||
defp upsert_conflict_check(changeset, subject, conflicting_upsert_values, opts_upsert_condition)
|
defp upsert_conflict_check(changeset, subject, conflicting_upsert_values)
|
||||||
|
|
||||||
defp upsert_conflict_check(
|
defp upsert_conflict_check(
|
||||||
%Ash.Changeset{filter: nil},
|
%Ash.Changeset{filter: nil},
|
||||||
result,
|
result,
|
||||||
_conflicting_upsert_values,
|
_conflicting_upsert_values
|
||||||
nil
|
|
||||||
),
|
),
|
||||||
do: {:ok, [result]}
|
do: {:ok, [result]}
|
||||||
|
|
||||||
defp upsert_conflict_check(
|
defp upsert_conflict_check(
|
||||||
%Ash.Changeset{filter: filter, domain: domain, context: context},
|
%Ash.Changeset{filter: filter, domain: domain, context: context},
|
||||||
result,
|
result,
|
||||||
conflicting_upsert_values,
|
conflicting_upsert_values
|
||||||
opts_upsert_condition
|
|
||||||
) do
|
) do
|
||||||
filter_matches(
|
filter_matches(
|
||||||
[result],
|
[result],
|
||||||
opts_upsert_condition || filter,
|
filter,
|
||||||
domain,
|
domain,
|
||||||
nil,
|
nil,
|
||||||
context[:tenant],
|
context[:tenant],
|
||||||
|
|
|
@ -3395,6 +3395,12 @@ defmodule Ash.Filter do
|
||||||
do_hydrate_refs(value, context)
|
do_hydrate_refs(value, context)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def do_hydrate_refs(%__MODULE__{expression: expression} = filter, context) do
|
||||||
|
with {:ok, expr} <- do_hydrate_refs(expression, context) do
|
||||||
|
{:ok, %{filter | expression: expr}}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def do_hydrate_refs({:_ref, value}, context) do
|
def do_hydrate_refs({:_ref, value}, context) do
|
||||||
do_hydrate_refs(
|
do_hydrate_refs(
|
||||||
%Ash.Query.Ref{
|
%Ash.Query.Ref{
|
||||||
|
|
Loading…
Reference in a new issue