5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-07-01 11:46:07 +00:00
panel/app/models/metadata_has_one.rb
2023-04-08 17:54:07 -03:00

30 lines
537 B
Ruby

# frozen_string_literal: true
class MetadataHasOne < MetadataBelongsTo
alias has_one belongs_to
alias had_one belonged_to
def save
# XXX: DRY
if !changed?
self[:value] = document_value
return true
end
self[:value] = sanitize value
return true unless changed?
return true unless inverse?
had_one[inverse]&.value = '' if had_one
has_one[inverse]&.value = post.uuid.value if has_one
true
end
def related_methods
@related_methods ||= %i[has_one had_one].freeze
end
end