diff --git a/app/models/metadata_has_one.rb b/app/models/metadata_has_one.rb index d1705e7d..0cadb1d9 100644 --- a/app/models/metadata_has_one.rb +++ b/app/models/metadata_has_one.rb @@ -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 diff --git a/app/services/post_service.rb b/app/services/post_service.rb index 91d8b8f6..23b54d11 100644 --- a/app/services/post_service.rb +++ b/app/services/post_service.rb @@ -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)