Skip to content

Commit d827326

Browse files
committed
fix: uniq linkage for display, but only when necessary
1 parent ce83c55 commit d827326

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lib/ash_json_api/serializer.ex

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ defmodule AshJsonApi.Serializer do
571571

572572
defp add_linkage(payload, record, %{destination: destination, cardinality: :one, name: name}) do
573573
case record do
574-
%{__linkage__: %{^name => [record]}} ->
574+
%{__linkage__: %{^name => [record | _]}} ->
575575
Map.put(payload, :data, %{
576576
id: AshJsonApi.Resource.encode_primary_key(record),
577577
type: AshJsonApi.Resource.Info.type(destination)
@@ -600,11 +600,12 @@ defmodule AshJsonApi.Serializer do
600600
Map.put(
601601
payload,
602602
:data,
603-
Enum.map(
604-
linkage,
603+
linkage
604+
|> Enum.map(
605605
&(%{id: AshJsonApi.Resource.encode_primary_key(&1), type: type}
606606
|> add_relationship_meta(&1, record, relationship))
607607
)
608+
|> Enum.uniq_by(& &1.id)
608609
)
609610

610611
_ ->

0 commit comments

Comments
 (0)