5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-10-01 22:46:59 +00:00
panel/app/models/metadata_has_one.rb

35 lines
547 B
Ruby
Raw Normal View History

2023-04-08 15:47:51 +00:00
# frozen_string_literal: true
class MetadataHasOne < MetadataHasMany
def had_one
return default_value if value_was.blank?
posts.find(uuid: value)
end
def has_one
return default_value if value.blank?
posts.find(uuid: value)
end
def had_many; end
def has_many; end
def save
super
return true unless changed?
return true unless inverse?
had_one&.value = nil
has_one&.value = post.uuid.value
true
end
def related_methods
@related_methods ||= %i[has_one had_one].freeze
end
2023-04-08 15:47:51 +00:00
end