mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-24 11:26:23 +00:00
29 lines
537 B
Ruby
29 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
|