mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-20 13:33:50 +12:00
fix: prevent ecto/pg from getting confused about the type of maps
This commit is contained in:
parent
1a4a508e39
commit
40481a17a0
2 changed files with 18 additions and 4 deletions
|
@ -1594,10 +1594,13 @@ defmodule AshPostgres.Expr do
|
||||||
|
|
||||||
defp do_dynamic_expr(query, value, bindings, embedded?, acc, _type)
|
defp do_dynamic_expr(query, value, bindings, embedded?, acc, _type)
|
||||||
when is_map(value) and not is_struct(value) do
|
when is_map(value) and not is_struct(value) do
|
||||||
|
{value, acc} =
|
||||||
Enum.reduce(value, {%{}, acc}, fn {key, value}, {map, acc} ->
|
Enum.reduce(value, {%{}, acc}, fn {key, value}, {map, acc} ->
|
||||||
{value, acc} = do_dynamic_expr(query, value, bindings, embedded?, acc)
|
{value, acc} = do_dynamic_expr(query, value, bindings, embedded?, acc)
|
||||||
{Map.put(map, key, value), acc}
|
{Map.put(map, key, value), acc}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
{Ecto.Query.dynamic([], type(^value, :map)), acc}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp do_dynamic_expr(query, other, bindings, true, acc, type) do
|
defp do_dynamic_expr(query, other, bindings, true, acc, type) do
|
||||||
|
|
|
@ -34,6 +34,17 @@ defmodule AshPostgres.BulkUpdateTest do
|
||||||
|> Enum.map(& &1.list_of_stuff)
|
|> Enum.map(& &1.list_of_stuff)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "a map can be given as input on a regular update" do
|
||||||
|
%{records: [post | _]} =
|
||||||
|
Api.bulk_create!([%{title: "fred"}, %{title: "george"}], Post, :create,
|
||||||
|
return_records?: true
|
||||||
|
)
|
||||||
|
|
||||||
|
post
|
||||||
|
|> Ash.Changeset.for_update(:update, %{list_of_stuff: [%{a: [:a, :b]}, %{a: [:c, :d]}]})
|
||||||
|
|> Api.update!()
|
||||||
|
end
|
||||||
|
|
||||||
test "bulk updates only apply to things that the query produces" do
|
test "bulk updates only apply to things that the query produces" do
|
||||||
Api.bulk_create!([%{title: "fred"}, %{title: "george"}], Post, :create)
|
Api.bulk_create!([%{title: "fred"}, %{title: "george"}], Post, :create)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue