lib/neo4j/active_rel/persistence.rb in neo4j-5.0.0 vs lib/neo4j/active_rel/persistence.rb in neo4j-5.0.1

- old
+ new

@@ -58,25 +58,29 @@ type = from_node == node ? :_from_class : :_to_class type_class = self.class.send(type) next if [:any, false].include?(type_class) - fail ModelClassInvalidError, "Node class was #{node.class}, expected #{type_class}" unless node.is_a?(type_class.to_s.constantize) + unless node.class.mapped_label_names.include?(type_class.to_s.constantize.mapped_label_name) + fail ModelClassInvalidError, type_validation_error_message(node, type_class) + end 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})" + end + def _create_rel(from_node, to_node, *args) props = self.class.default_property_values(self) props.merge!(args[0]) if args[0].is_a?(Hash) set_classname(props, true) if from_node.id.nil? || to_node.id.nil? fail RelCreateFailedError, "Unable to create relationship (id is nil). from_node: #{from_node}, to_node: #{to_node}" end _rel_creation_query(from_node, to_node, props) end - - private N1_N2_STRING = 'n1, n2' ACTIVEREL_NODE_MATCH_STRING = 'ID(n1) = {n1_neo_id} AND ID(n2) = {n2_neo_id}' def _rel_creation_query(from_node, to_node, props) Neo4j::Session.query.match(N1_N2_STRING)