5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-26 06:56:22 +00:00

Merge branch 'issue-12985' into panel.sutty.nl

This commit is contained in:
f 2023-04-10 11:50:44 -03:00
commit a7eb1cab9b
2 changed files with 14 additions and 19 deletions

View file

@ -41,7 +41,7 @@ class MetadataBelongsTo < MetadataRelatedPosts
# anterior # anterior
if belonged_to.present? if belonged_to.present?
if belonged_to[inverse].respond_to? :has_one if belonged_to[inverse].respond_to? :has_one
belonged_to[inverse].value = nil belonged_to[inverse].value = ''
else else
belonged_to[inverse].value = belonged_to[inverse].value.reject do |rej| belonged_to[inverse].value = belonged_to[inverse].value.reject do |rej|
rej == post.uuid.value rej == post.uuid.value

View file

@ -1,29 +1,24 @@
# frozen_string_literal: true # frozen_string_literal: true
class MetadataHasOne < MetadataHasMany class MetadataHasOne < MetadataBelongsTo
def had_one alias has_one belongs_to
return default_value if value_was.blank? alias had_one belonged_to
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 def save
super # XXX: DRY
if !changed?
self[:value] = document_value
return true
end
self[:value] = sanitize value
return true unless changed? return true unless changed?
return true unless inverse? return true unless inverse?
had_one&.value = nil had_one[inverse]&.value = '' if had_one
has_one&.value = post.uuid.value has_one[inverse]&.value = post.uuid.value if has_one
true true
end end