Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActiveRel record where statement problem... #1477

Open
softwareeverything opened this issue Jan 27, 2018 · 1 comment
Open

ActiveRel record where statement problem... #1477

softwareeverything opened this issue Jan 27, 2018 · 1 comment

Comments

@softwareeverything
Copy link

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

@cheerfulstoic
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants