From 528509b52cc3c4315e1acef2c4313e8d1577ccc2 Mon Sep 17 00:00:00 2001 From: d-m-u Date: Thu, 1 Oct 2020 19:45:39 -0400 Subject: [PATCH] add ancestry case to the genealogy parent setter when we destroy all relationships, we'll want to alias this setter to parent= --- app/models/vm_or_template.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/models/vm_or_template.rb b/app/models/vm_or_template.rb index aaff73f9c50..ba73f45cc94 100644 --- a/app/models/vm_or_template.rb +++ b/app/models/vm_or_template.rb @@ -529,9 +529,19 @@ def genealogy_parent end def genealogy_parent=(parent) - @genealogy_parent_object = parent + with_relationship_type('genealogy') do + if use_ancestry? + self.parent = parent + else + @genealogy_parent_object = parent + end + end end + # save_genealogy_information is only necessary for relationships using genealogy + # when using ancestry, the relationship will be saved after the fact + # when not using ancestry, the relationship is saved on assignment, necessitating the prior save of the vm/template record + # this variable is used to delay that assignment def save_genealogy_information if defined?(@genealogy_parent_object) && @genealogy_parent_object with_relationship_type('genealogy') { self.parent = @genealogy_parent_object }