lib/neo4j/active_rel/persistence.rb in neo4j-3.0.3 vs lib/neo4j/active_rel/persistence.rb in neo4j-3.0.4
- old
+ new
@@ -2,12 +2,12 @@
module Persistence
extend ActiveSupport::Concern
include Neo4j::Shared::Persistence
class RelInvalidError < RuntimeError; end
-
class ModelClassInvalidError < RuntimeError; end
+ class RelCreateFailedError < RuntimeError; end
def clear_association_cache; end
def save(*)
update_magic_properties
@@ -84,15 +84,19 @@
private
def _rel_creation_query(from_node, to_node, props)
from_class = from_node.class
to_class = to_node.class
- Neo4j::Session.query.match(n1: from_class.mapped_label_name, n2: to_class.mapped_label_name)
- .where("n1.#{from_class.primary_key} = {from_node_id}")
- .where("n2.#{to_class.primary_key} = {to_node_id}")
- .params(from_node_id: from_node.id, to_node_id: to_node.id)
- .create("(n1)-[r:`#{type}`]->(n2)")
- .with('r').set(r: props).return(:r).first.r
+ begin
+ Neo4j::Session.query.match(n1: from_class.mapped_label_name, n2: to_class.mapped_label_name)
+ .where("n1.#{from_class.primary_key} = {from_node_id}")
+ .where("n2.#{to_class.primary_key} = {to_node_id}")
+ .params(from_node_id: from_node.id, to_node_id: to_node.id)
+ .create("(n1)-[r:`#{type}`]->(n2)")
+ .with('r').set(r: props).return(:r).first.r
+ rescue NoMethodError
+ raise RelCreateFailedError, "Unable to create relationship. from_node: #{from_node}, to_node: #{to_node}"
+ end
end
end
end
\ No newline at end of file