我有一个用户讲几种语言。我正在编写一个查询,以找出用户是否会说英语。我想通过搜索用户节点和语言节点之间是否存在关系来确定用户是否说英语。我用的是rel。To_other或rel_others。两者都失败了,如下所述。顺便说一句,"to_other"one_answers"to_others"方法之间的区别是什么?
irb(main):105:0> u
=> #<User uuid: "b1461edd-a574-44a7-9555-68659a361be2", created_at: Tue, 06 Oct 2015 16:21:26 +0000, name: "Levi Damian", type: "Regular", updated_at: Tue, 06 Oct 2015 16:21:26 +0000>
irb(main):106:0> l
=> #<Language uuid: "e388eb70-66b2-4b20-8f15-6ca11b34d03d", name: "English">
irb(main):107:0> u.rels.to_other(l)
CYPHER 802ms MATCH n, (n)-[r]-(p) WHERE (ID(n) = {ID_n}) RETURN r as result | {:ID_n=>38}
NoMethodError: CYPHER 125ms MATCH n WHERE (ID(n) = {ID_n}) RETURN n | {:ID_n=>38}
CYPHER 125ms MATCH n WHERE (ID(n) = {ID_n}) RETURN n | {:ID_n=>43}
CYPHER 125ms MATCH n WHERE (ID(n) = {ID_n}) RETURN n | {:ID_n=>38}
CYPHER 124ms MATCH n WHERE (ID(n) = {ID_n}) RETURN n | {:ID_n=>42}
CYPHER 128ms MATCH n WHERE (ID(n) = {ID_n}) RETURN n | {:ID_n=>38}
CYPHER 130ms MATCH n WHERE (ID(n) = {ID_n}) RETURN n | {:ID_n=>41}
CYPHER 124ms MATCH n WHERE (ID(n) = {ID_n}) RETURN n | {:ID_n=>38}
CYPHER 125ms MATCH n WHERE (ID(n) = {ID_n}) RETURN n | {:ID_n=>86}
CYPHER 124ms MATCH n WHERE (ID(n) = {ID_n}) RETURN n | {:ID_n=>38}
CYPHER 129ms MATCH n WHERE (ID(n) = {ID_n}) RETURN n | {:ID_n=>87}
undefined method `to_other' for #<Array:0x007fedc2d6b980>
from (irb):107
from /Users/levi/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/commands/console.rb:110:in `start'
为什么会出现这个错误,我怎样才能使它工作?
rels
立即返回该节点到…的所有关系。一切。它返回一个数组,因此出现错误。如果您有一个具有许多关系的节点,那么它可能是一个非常缓慢的内存密集型操作。
假设你的模型中有一个languages
关联,你可以用u.languages.match_to(l).exists?
代替。它将返回一个布尔值,不返回任何图形对象。您也可以使用blank?
或empty?