8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/json_api/active_storage/serialization.rb', line 8
def serialize_relationship(attachment_name, record)
return nil unless defined?(::ActiveStorage)
attachment = record.public_send(attachment_name)
if attachment.respond_to?(:attached?) && attachment.attached?
if attachment.is_a?(::ActiveStorage::Attached::Many)
attachment.blobs.map { |blob| serialize_blob_identifier(blob) }
else
serialize_blob_identifier(attachment.blob)
end
elsif attachment.respond_to?(:attached?) && !attachment.attached?
attachment.is_a?(::ActiveStorage::Attached::Many) ? [] : nil
end
end
|