From a51dc7aa1851fbd357b511eddb59a2a47373a615 Mon Sep 17 00:00:00 2001 From: Carlo Beltrame Date: Tue, 20 Dec 2022 11:41:24 +0100 Subject: [PATCH] Fix nested validations ActiveRecord objects are compared by id only. The |= operator would ignore any children which are only updated, i.e. whose id has not changed. By reversing the `target = target | [child]` logic to `target = [child] | target`, we elect to keep the child with its updated attributes. This is relevant for detecting validation errors in the child later. --- lib/graphiti/adapters/active_record.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/graphiti/adapters/active_record.rb b/lib/graphiti/adapters/active_record.rb index 3cedfae6..2b8c0492 100644 --- a/lib/graphiti/adapters/active_record.rb +++ b/lib/graphiti/adapters/active_record.rb @@ -248,7 +248,7 @@ def associate_all(parent, children, association_name, association_type) parent.send(association_name) << child else target = association.instance_variable_get(:@target) - target |= [child] + target = [child] | target association.instance_variable_set(:@target, target) end end