mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-29 21:16:22 +00:00
parent
fabcabc100
commit
0eee4f17d3
1 changed files with 16 additions and 11 deletions
|
@ -199,10 +199,7 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do
|
|||
end
|
||||
|
||||
associated_posts(value - value_was).each do |add_post|
|
||||
add_post[inverse_attribute].value << post.uuid.value
|
||||
add_post[inverse_attribute].value.uniq!
|
||||
|
||||
associated_posts_to_save << add_post
|
||||
add_relation_to(add_post[inverse_attribute], post.uuid.value)
|
||||
end
|
||||
when 'has_many'
|
||||
associated_posts(value_was - value).each do |remove_post|
|
||||
|
@ -214,9 +211,7 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do
|
|||
remove_relation_from(remove_post[attribute], add_post.uuid.value)
|
||||
end
|
||||
|
||||
add_post[inverse_attribute].value = post.uuid.value
|
||||
|
||||
associated_posts_to_save << add_post
|
||||
add_relation_to(add_post[inverse_attribute], post.uuid.value)
|
||||
end
|
||||
when 'belongs_to'
|
||||
if value_was.present?
|
||||
|
@ -226,10 +221,7 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do
|
|||
end
|
||||
|
||||
associated_posts(value).each do |add_post|
|
||||
add_post[inverse_attribute].value << post.uuid.value
|
||||
add_post[inverse_attribute].value.uniq!
|
||||
|
||||
associated_posts_to_save << add_post
|
||||
add_relation_to(add_post[inverse_attribute], post.uuid.value)
|
||||
end
|
||||
when 'locales'
|
||||
end
|
||||
|
@ -246,4 +238,17 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do
|
|||
associated_posts_to_save << metadata.post
|
||||
nil
|
||||
end
|
||||
|
||||
# @todo El validador ya debería eliminar valores duplicados
|
||||
def add_relation_to(metadata, value)
|
||||
case metadata.value
|
||||
when Array
|
||||
metadata.value << value
|
||||
metadata.uniq!
|
||||
when String then metadata.value = value
|
||||
end
|
||||
|
||||
associated_posts_to_save << metadata.post
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue