mirror of
https://github.com/ditkrg/jsonapi-deserializable.git
synced 2026-01-22 22:06:47 +00:00
Merge 65826973f0 into 726d6828db
This commit is contained in:
commit
dc0322d7f2
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user