lib/neo4j/active_rel/persistence.rb in neo4j-5.2.15 vs lib/neo4j/active_rel/persistence.rb in neo4j-6.0.0.alpha.1

- old
+ new

@@ -10,11 +10,11 @@ def save(*) create_or_update end def save!(*args) - fail RelInvalidError, self unless save(*args) + save(*args) or fail(RelInvalidError, self) # rubocop:disable Style/AndOr end def create_model validate_node_classes! rel = _create_rel(from_node, to_node, props_for_create) @@ -58,14 +58,23 @@ def validate_node_classes! [from_node, to_node].each do |node| type = from_node == node ? :_from_class : :_to_class type_class = self.class.send(type) - next if [:any, false].include?(type_class) - - unless node.class.mapped_label_names.include?(type_class.to_s.constantize.mapped_label_name) + unless valid_type?(type_class, node) fail ModelClassInvalidError, type_validation_error_message(node, type_class) end + end + end + + def valid_type?(type_object, node) + case type_object + when false, :any + true + when Array + type_object.any? { |c| valid_type?(c, node) } + else + node.class.mapped_label_names.include?(type_object.to_s.constantize.mapped_label_name) end end def type_validation_error_message(node, type_class) "Node class was #{node.class} (#{node.class.object_id}), expected #{type_class} (#{type_class.object_id})"