mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-23 01:26:22 +00:00
(cherry picked from commit 74ae4ef4ab
)
This commit is contained in:
parent
3b3b79a22d
commit
eda06ae26f
2 changed files with 2 additions and 28 deletions
|
@ -1,29 +1,3 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class MetadataHasOne < MetadataBelongsTo
|
class MetadataHasOne < MetadataBelongsTo; end
|
||||||
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
|
|
||||||
|
|
|
@ -222,7 +222,7 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do
|
||||||
|
|
||||||
add_relation_to(add_post[inverse_attribute], post.uuid.value)
|
add_relation_to(add_post[inverse_attribute], post.uuid.value)
|
||||||
end
|
end
|
||||||
when 'belongs_to'
|
when 'belongs_to', 'has_one'
|
||||||
if value_was.present?
|
if value_was.present?
|
||||||
associated_posts(value_was).each do |remove_post|
|
associated_posts(value_was).each do |remove_post|
|
||||||
remove_relation_from(remove_post[inverse_attribute], value_was)
|
remove_relation_from(remove_post[inverse_attribute], value_was)
|
||||||
|
|
Loading…
Reference in a new issue