Skip to content

Commit 3962e38

Browse files
barelyknownlgebhardt
authored andcommitted
avoid situation where the linkage data could be partially calculated
(cherry picked from commit 49c8bc6)
1 parent 895be34 commit 3962e38

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

lib/jsonapi/resource_serializer.rb

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -247,24 +247,22 @@ def related_link(source, relationship)
247247
end
248248

249249
def to_one_linkage(source, relationship)
250-
linkage = {}
251-
linkage_id = foreign_key_value(source, relationship)
252-
253-
if linkage_id
254-
linkage[:type] = format_key(relationship.type_for_source(source))
255-
linkage[:id] = linkage_id
256-
else
257-
linkage = nil
258-
end
259-
linkage
250+
return unless linkage_id = foreign_key_value(source, relationship)
251+
return unless linkage_type = format_key(relationship.type_for_source(source))
252+
{
253+
type: linkage_type,
254+
id: linkage_id,
255+
}
260256
end
261257

262258
def to_many_linkage(source, relationship)
263259
linkage = []
264260
linkage_types_and_values = foreign_key_types_and_values(source, relationship)
265261

266262
linkage_types_and_values.each do |type, value|
267-
linkage.append({type: format_key(type), id: value})
263+
if type && value
264+
linkage.append({type: format_key(type), id: @id_formatter.format(value)})
265+
end
268266
end
269267
linkage
270268
end

0 commit comments

Comments
 (0)