mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-25 23:06:22 +00:00
Merge branch 'issue-12985' into panel.sutty.nl
This commit is contained in:
commit
a7eb1cab9b
2 changed files with 14 additions and 19 deletions
|
@ -41,7 +41,7 @@ class MetadataBelongsTo < MetadataRelatedPosts
|
|||
# anterior
|
||||
if belonged_to.present?
|
||||
if belonged_to[inverse].respond_to? :has_one
|
||||
belonged_to[inverse].value = nil
|
||||
belonged_to[inverse].value = ''
|
||||
else
|
||||
belonged_to[inverse].value = belonged_to[inverse].value.reject do |rej|
|
||||
rej == post.uuid.value
|
||||
|
|
|
@ -1,29 +1,24 @@
|
|||
# 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
|
||||
class MetadataHasOne < MetadataBelongsTo
|
||||
alias has_one belongs_to
|
||||
alias had_one belonged_to
|
||||
|
||||
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 inverse?
|
||||
|
||||
had_one&.value = nil
|
||||
has_one&.value = post.uuid.value
|
||||
had_one[inverse]&.value = '' if had_one
|
||||
has_one[inverse]&.value = post.uuid.value if has_one
|
||||
|
||||
true
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue