@@ -151,7 +151,7 @@ defmodule AshJsonApi.Serializer do
151
151
152
152
defp serialize_relationship_data ( record , source_record , relationship ) do
153
153
% {
154
- id: record . id ,
154
+ id: AshJsonApi.Resource . encode_primary_key ( record ) ,
155
155
type: AshJsonApi.Resource.Info . type ( relationship . destination )
156
156
}
157
157
|> add_relationship_meta ( record , source_record , relationship )
@@ -569,8 +569,11 @@ defmodule AshJsonApi.Serializer do
569
569
570
570
defp add_linkage ( payload , record , % { destination: destination , cardinality: :one , name: name } ) do
571
571
case record do
572
- % { __linkage__: % { ^ name => [ % { id: id } ] } } ->
573
- Map . put ( payload , :data , % { id: id , type: AshJsonApi.Resource.Info . type ( destination ) } )
572
+ % { __linkage__: % { ^ name => [ record ] } } ->
573
+ Map . put ( payload , :data , % {
574
+ id: AshJsonApi.Resource . encode_primary_key ( record ) ,
575
+ type: AshJsonApi.Resource.Info . type ( destination )
576
+ } )
574
577
575
578
# There could be another case here if a bug in the system gave us a list
576
579
# of more than one shouldn't happen though
@@ -594,7 +597,8 @@ defmodule AshJsonApi.Serializer do
594
597
:data ,
595
598
Enum . map (
596
599
linkage ,
597
- & ( % { id: & 1 . id , type: type } |> add_relationship_meta ( & 1 , record , relationship ) )
600
+ & ( % { id: AshJsonApi.Resource . encode_primary_key ( record ) , type: type }
601
+ |> add_relationship_meta ( & 1 , record , relationship ) )
598
602
)
599
603
)
600
604
0 commit comments