activegraph icon indicating copy to clipboard operation
activegraph copied to clipboard

ActiveRel record where statement problem...

Open softwareeverything opened this issue 6 years ago • 1 comments

If I code;

r = Rel.where(from_node: node1, to_node: node2).first
r.update_attributes!(...)

I'm getting an error at the first line and the problem is;

The parsed cypher is: MATCH(...) WHERE (node1=node1, node2=node2) RETURN ...

At where statement it puts comma instead of and. How can I fix it?

Runtime information:

Neo4j database version: neo4j 3.3.1 neo4j gem version: 9.0.7 neo4j-core gem version: 8.1.0

softwareeverything avatar Jan 27 '18 16:01 softwareeverything

That's actually strange. I think maybe .where was supposed to be removed from ActiveRel but didn't get removed completely.

Neo4j encourages making queries starting with nodes rather than relationships. Nodes can have indexes but relationships don't. Thus the design of the neo4j gems follows suit. Do do that query I would have an association from the node. Something like:

class SourceModel
  include Neo4j::ActiveNode

  has_one :out, :association_name, rel_class: :Rel
end

node1.association_proxy(:association_name).each_rel.first

# If the association is `has_many` instead of `has_one` you already get an `association_proxy` when calling the association:

node1.association_name.each_rel.first

There's been talk of having a method like association_name_rel which would allow you to get the relationship for a has_one association and that would mean the first line would just be node1.association_proxy_rel, which would be a nicer syntax.

cheerfulstoic avatar Jan 29 '18 02:01 cheerfulstoic