mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 05:23:03 +12:00
improvement: sort relationship in order of input when managing it
This helps with things like https://github.com/ash-project/ash_phoenix/issues/57 which involve rendering the relationship value after editing it. Retaining the order allows direct reuse without any gymnastics
This commit is contained in:
parent
5a11736931
commit
235e965627
2 changed files with 10 additions and 3 deletions
|
@ -645,6 +645,13 @@ defmodule Ash.Actions.ManagedRelationships do
|
|||
opts
|
||||
) do
|
||||
{:ok, new_value, notifications} ->
|
||||
new_value =
|
||||
if is_list(new_value) do
|
||||
Enum.reverse(new_value)
|
||||
else
|
||||
new_value
|
||||
end
|
||||
|
||||
{:ok, Map.put(record, relationship.name, new_value),
|
||||
all_notifications ++ notifications}
|
||||
|
||||
|
|
|
@ -580,11 +580,11 @@ defmodule Ash.Test.Actions.CreateTest do
|
|||
|> Api.create!()
|
||||
|> strip_metadata()
|
||||
|
||||
assert Enum.sort(post.related_posts) ==
|
||||
Enum.sort([
|
||||
assert post.related_posts ==
|
||||
[
|
||||
Api.get!(Post, post2.id),
|
||||
Api.get!(Post, post3.id)
|
||||
])
|
||||
]
|
||||
|> strip_metadata()
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue