这是我的 Neo4j 活动节点
class User
include Neo4j::ActiveNode
has_many :out, :following, type: :following, model_class: 'User'
end
john = User.find(:name => "John")
tom = User.find(:name => "Tom")
# create following relationship john --> tom
john.following << tom
# check count
john.following.count
#=> 1
# again create the relationship
john.following << tom
# again check count
john.following.count
#=> 2
我想建立独特的关系。
为了避免重复,我们必须在创建关系密码查询时使用 create unique。
Example:
MATCH (root { name: 'root' })
CREATE UNIQUE (root)-[:LOVES]-(someone)
RETURN someone
refer: http://neo4j.com/docs/stable/query-create-unique.html http://neo4j.com/docs/stable/query-create-unique.html
我如何使用 Rails 在 Neo4j.rb 中执行此操作...?
提前致谢..
正如更新一样,您现在可以执行以下操作:
对于简单的关系,使用unique:true
:
class User
include Neo4j::ActiveNode
has_many :out, :following, type: :following, model_class: 'User', unique: true
end
对于声明的关系,使用creates_unique
:
class Following
include Neo4j::ActiveRel
creates_unique
from_class User
to_class User
end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)