-
Notifications
You must be signed in to change notification settings - Fork 276
Neo4j::Cypher Return
Unlike the original cypher language you can specify a return value at any place in the DSL. If you don't specify a return value it will try to return the last value evaluated in the DSL.
node(2)
node(3)
Will generate the following Cypher string: START v1=node(2),v2=node(3) RETURN v2
If you want to return both nodes in the example above you can either return an array or use the ret
method (see below).
Example of returning an array
[node(2), node(3)]
Will generate: START v1=node(2),v2=node(3) RETURN v1,v2
Example, specify the variable names (see Neo4j::Cypher-Start
[node(2).as(:x), node(3).as(:y)]
Will generate: START x=node(2),y=node(3) RETURN x,y
Instead of returning an Ruby array you can specify the return values using the ret
method.
ret(node(1), node(2))
Will generate: START v1=node(1),v2=node(2) RETURN v1,v2
Notice that you don't have to use the ret method in the last evaluated expression. A silly example:
ret(node(2))
node(3)
Will return: START v1=node(2),v2=node(3) RETURN v1
Ruby symbols corresponds to the cypher variable names.
node(2).as(:foo) >> :bar; :bar
Will generate: START foo=node(2) MATCH (foo)-->(bar) RETURN bar
The symbols can also be used in the ret method, example
node(2) >> :x >> :y
ret :x, :y
Will generate: START v1=node(2) MATCH (v1)-->(x)-->(y) RETURN x,y
The ret
method is also available on paths, nodes, relationships and properties !
This allows you to specify the return value immediately.
Instead of the two line example above you can write that in one line like this:
node(2) >> node(:x).ret >> node(:y).ret
Will generate: START v1=node(2) MATCH (v1)-->(x)-->(y) RETURN x,y
WARNING: Much of the information in this wiki is out of date. We are in the process of moving things to readthedocs
- Project Introduction
- Neo4j::ActiveNode
- Neo4j::ActiveRel
- Search and Scope
- Validation, Uniqueness, and Case Sensitivity
- Indexing VS Legacy Indexing
- Optimized Methods
- Inheritance
- Core: Nodes & Rels
- Introduction
- Persistence
- Find : Lucene
- Relationships
- Third Party Gems & extensions
- Scaffolding & Generators
- HA Cluster