From 522494de5ab61e90e18ce1720aee316800cb2276 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 11 Feb 2021 17:57:12 -0300 Subject: [PATCH] validar relaciones correctamente --- app/models/metadata_belongs_to.rb | 4 +++- app/models/metadata_has_many.rb | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/metadata_belongs_to.rb b/app/models/metadata_belongs_to.rb index 27c50f90..0626ba0c 100644 --- a/app/models/metadata_belongs_to.rb +++ b/app/models/metadata_belongs_to.rb @@ -90,7 +90,9 @@ class MetadataBelongsTo < MetadataRelatedPosts private def post_exists? - value.present? && belongs_to.nil? + return true if sanitize(value).blank? + + sanitize(value).present? && belongs_to.present? end def sanitize(uuid) diff --git a/app/models/metadata_has_many.rb b/app/models/metadata_has_many.rb index ec79ddba..61354011 100644 --- a/app/models/metadata_has_many.rb +++ b/app/models/metadata_has_many.rb @@ -73,6 +73,6 @@ class MetadataHasMany < MetadataRelatedPosts end def posts_exist? - has_many.size == value.size + has_many.size == sanitize(value).size end end