1

我想找到所有尚未与我的 Bar 关联的 Foo。我使用 neo4j.rb (4.1.2) 和 Rails (4.2)。我现在使用的产生正确输出但感觉不理想的代码是:

@foos = Foo.all.find_all do |foo|
  foo.bars.rels_to(current_bar).count == 0
end 

有没有更好的方法用 Cypher 做到这一点?

4

1 回答 1

6

这是在 Cypher 中执行此操作的一种方法。我假设您只对直接关系感兴趣,并且Bar节点由id属性标识。

MATCH (b:Bar), (f:Foo)
WHERE b.id = 123 AND NOT (b)--(f)
RETURN b, COLLECT(f);
于 2015-02-04T22:03:52.247 回答