This commit is contained in:
Ari Karim 2024-04-28 12:15:17 +03:00 committed by GitHub
commit dc0322d7f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -189,7 +189,7 @@ module JSONAPI
register_mappings(hash.keys, "/relationships/#{key}")
if options.[](:with_included)
if options.[](:with_included) && id.present? && type.present?
return {**hash, key.to_sym => find_in_included(id:, type:)}
end
@ -225,7 +225,7 @@ module JSONAPI
cross_reference = @included.select { |doc| doc[:object]&.instance_variable_get(:@id) == id && doc[:object].instance_variable_get(:@type) == type }&.first
# If the deserializer is created using a given class, we will need to call .to_h on it instead of plucking all its attributes
cross_reference[:has_deserializer] ? cross_reference[:object].to_h : cross_reference[:object].instance_variable_get(:@attributes).to_h
cross_reference[:has_deserializer] ? cross_reference[:object].to_h : cross_reference[:object].instance_variable_get(:@attributes).to_h.merge({ id: id, type: type })
end
# rubocop: enable Metrics/AbcSize
end