mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-22 15:46:21 +00:00
fix: has_one es como belongs_to
This commit is contained in:
parent
a8485a9745
commit
74ae4ef4ab
2 changed files with 2 additions and 28 deletions
|
@ -1,29 +1,3 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class MetadataHasOne < MetadataBelongsTo
|
||||
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
|
||||
class MetadataHasOne < MetadataBelongsTo; 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)
|
||||
end
|
||||
when 'belongs_to'
|
||||
when 'belongs_to', 'has_one'
|
||||
if value_was.present?
|
||||
associated_posts(value_was).each do |remove_post|
|
||||
remove_relation_from(remove_post[inverse_attribute], value_was)
|
||||
|
|
Loading…
Reference in a new issue