5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-22 20:16:23 +00:00
panel/app/models/metadata_has_one.rb

30 lines
537 B
Ruby
Raw Normal View History

2023-04-08 15:47:51 +00:00
# frozen_string_literal: true
2023-04-08 20:36:13 +00:00
class MetadataHasOne < MetadataBelongsTo
2023-04-08 20:45:02 +00:00
alias has_one belongs_to
alias had_one belonged_to
def save
2023-04-08 20:36:13 +00:00
# XXX: DRY
if !changed?
self[:value] = document_value
return true
end
self[:value] = sanitize value
return true unless changed?
return true unless inverse?
2023-04-08 20:54:07 +00:00
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
2023-04-08 15:47:51 +00:00
end