Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions lib/jsonapi/resource_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -353,16 +353,14 @@ def related_link(source, relationship)
end

def to_one_linkage(source, relationship)
linkage = {}
linkage_id = foreign_key_value(source, relationship)
linkage_type = format_key(relationship.type_for_source(source))
return unless linkage_id.present? && linkage_type.present?

if linkage_id
linkage[:type] = format_key(relationship.type_for_source(source))
linkage[:id] = linkage_id
else
linkage = nil
end
linkage
{
type: linkage_type,
id: linkage_id,
}
end

def to_many_linkage(source, relationship)
Expand Down Expand Up @@ -390,7 +388,9 @@ def to_many_linkage(source, relationship)
end

linkage_types_and_values.each do |type, value|
linkage.append({type: format_key(type), id: @id_formatter.format(value)})
if type && value
linkage.append({type: format_key(type), id: @id_formatter.format(value)})
end
end
linkage
end
Expand Down