我一直在尝试将neography用于以下基本用例,但似乎无法使其正常工作:
- 对于给定的节点,告诉我该节点的所有关联关系。
- 对于给定节点和特定关系,返回该关系中的一个或多个节点?
我按照这里的例子:https ://maxdemarzi.com/2012/01/04/getting-started-with-ruby-and-neo4j/
我尝试了以下代码:
def create_person(name)
Neography::Node.create("name" => name)
end
johnathan = create_person('Johnathan')
mark = create_person('Mark')
phil = create_person('Phil')
mary = create_person('Mary')
luke = create_person('Luke')
johnathan.both(:friends) << mark
首先,我想查看传入的关联关系。我的期望是看到与 type 的关系:friends
:
johnathan.incoming
=> #<Neography::NodeTraverser:0x0000000133f1c0 @from=#<Neography::Node name="Johnathan">, @order="depth first", @uniqueness="none", @relationships=[{"type"=>"", "direction"=>"in"}]>
我试过relationships
:
2.2.1 :060 > johnathan.incoming.relationships
=> [{"type"=>"", "direction"=>"in"}]
我的期望是看到"type"=>":friends"
,但我没有。
但是,当我尝试以下操作时,我会这样做,但它不适用于我的用例,因为我想知道这些关系是什么而不事先知道它们是什么:
2.2.1 :061 > johnathan.incoming(:friends).relationships
=> [{"type"=>"friends", "direction"=>"in"}]
第二个用例是实际检索节点,这确实有效。
问题: 如何获得与任何给定节点关联的关系类型?
我想我已经接近弄清楚了:
johnathan.rels.map{|n| n}.first.rel_type
=> "friends"