lib/neo4j/active_rel.rb in neo4j-6.0.0.alpha.11 vs lib/neo4j/active_rel.rb in neo4j-6.0.0.alpha.12

- old
+ new

@@ -17,11 +17,13 @@ class FrozenRelError < StandardError; end def initialize(from_node = nil, to_node = nil, args = nil) load_nodes(node_or_nil(from_node), node_or_nil(to_node)) - super(hash_or_nil(from_node, args)) + resolved_args = hash_or_nil(from_node, args) + symbol_args = resolved_args.is_a?(Hash) ? resolved_args.symbolize_keys : resolved_args + super(symbol_args) end def node_cypher_representation(node) node_class = node.class id_name = node_class.id_property_name @@ -50,8 +52,27 @@ node.is_a?(Neo4j::ActiveNode) || node.is_a?(Integer) ? node : nil end def hash_or_nil(node_or_hash, hash_or_nil) node_or_hash.is_a?(Hash) ? node_or_hash : hash_or_nil + end + + module ClassMethods + [:create, :create!].each do |meth| + define_method(meth) do |from_node_or_args = nil, to_node = nil, args = nil| + return super(from_node_or_args) if from_node_or_args.is_a?(Hash) + args_hash = args || {} + args_with_node!(:from_node, from_node_or_args, args_hash) + args_with_node!(:to_node, to_node, args_hash) + super(args_hash) + end + end + + private + + def args_with_node!(key, node, args) + args[key] = node if node.is_a?(Neo4j::ActiveNode) + args + end end end end