2015-01-31 41 views

回答

4

我不认为这是可能的纯CYPHER查询。下面是使用,我认为将工作neo4j.rb一个解决方案:

# Assuming node1 already loaded 
node_query = Neo4j::Session.query.match(node: {neo_id: node1.neo_id}) 

types = node_query.match('node-[rel]-()').pluck('DISTINCT type(rel)') 

types.each do |type| 
    node_query.match('node-[rel]->(other)').with(:node, :rel, :other).create("node-[new_rel]->other").set('new_rel = rel').exec 
    node_query.match('node<-[rel]-(other)').with(:node, :rel, :other).create("node<-[new_rel]-other").set('new_rel = rel').exec 
end 
+0

我得到的类型,但随后在每次循环我不知道如何指定new_rel其他节点。 再次感谢Brian;) – armedwing 2015-02-01 13:03:15

+0

只是编辑,因为第二个查询是在错误的方向,他们都需要一个'执行' – 2015-02-01 13:57:12

+0

另一个节点正在由'other'变量指定。这应该在'WITH'子句中传递,然后在'CREATE'子句中再次匹配。我可能会误解...... – 2015-02-01 13:57:57

相关问题