5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-22 21:36:21 +00:00

fix: has_one es como belongs_to
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

(cherry picked from commit 74ae4ef4ab)
This commit is contained in:
f 2023-10-26 19:07:11 -03:00
parent 3b3b79a22d
commit eda06ae26f
No known key found for this signature in database
2 changed files with 2 additions and 28 deletions

View file

@ -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

View file

@ -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)