我使用ActiveNode
模型并使用neo4j gem在我的项目中创建了5个模型。
有一个名为Disease的模型,定义为:
class Disease
include Neo4j::ActiveNode
property :disease, type: String, constraint: :unique
property :created_at, type: DateTime
property :updated_at, type: DateTime
enum factor_effect: [:relief, :worsen]
# Associations
has_many :in, :factors, type: :AFFECTED_BY
end
和因素:
class Factor
include Neo4j::ActiveNode
property :factor, type: String, constraint: :unique
end
我可以轻松地为Factor创建节点但是对于Disease,它会给create
函数带来错误,并返回带有new
方法的QueryProxy对象。 (至于其他模型,它们也像因素一样正常工作)
以下是在控制台上运行的一些命令:
2.3.3 :012 > f = Factor.new
=> #<Factor uuid: nil, factor: nil>
2.3.3 :013 > f.factor = "drinking more water"
=> "drinking more water"
2.3.3 :014 > f
=> #<Factor uuid: nil, factor: "drinking more water">
2.3.3 :015 > f.save
HTTP REQUEST: 49ms GET http://localhost:7474/db/data/schema/constraint (0 bytes)
HTTP REQUEST: 8ms GET http://localhost:7474/db/data/schema/index (0 bytes)
WARNING: The constraint option is no longer supported (Defined on Disease for disease)
WARNING: The constraint option is no longer supported (Defined on Factor for factor)
CYPHER CREATE (n:`Factor`) SET n = {props} RETURN n | {:props=>{:uuid=>"33f683d4-a6b2-4c7a-84f9-549088780033", :factor=>"drinking more water"}}
HTTP REQUEST: 682ms POST http://localhost:7474/db/data/transaction (1 bytes)
HTTP REQUEST: 385ms POST http://localhost:7474/db/data/transaction/5/commit (0 bytes)
WARNING: The constraint option is no longer supported (Defined on Disease for disease)
WARNING: The constraint option is no longer supported (Defined on Factor for factor)
=> true
2.3.3 :016 > f
=> #<Factor uuid: "33f683d4-a6b2-4c7a-84f9-549088780033", factor: "drinking more water">
因此很容易创建Factor
节点。虽然有几个警告,我想知道原因。
当我为疾病做同样的事情时:
2.3.3 :020 > d = Disease.new
WARNING: The constraint option is no longer supported (Defined on Disease for disease)
WARNING: The constraint option is no longer supported (Defined on Factor for factor)
CYPHER
MATCH (result_disease:`Disease`)
RETURN result_disease
HTTP REQUEST: 82ms POST http://localhost:7474/db/data/transaction/commit (1 bytes)
=> #<QueryProxy []>
2.3.3 :021 > Disease.all
WARNING: The constraint option is no longer supported (Defined on Disease for disease)
WARNING: The constraint option is no longer supported (Defined on Factor for factor)
Disease
MATCH (n:`Disease`)
RETURN n
HTTP REQUEST: 11ms POST http://localhost:7474/db/data/transaction/commit (1 bytes)
=> #<QueryProxy Disease []>
它对我来说非常糟糕,我没有得到任何解决方法。请帮忙!!
答案 0 :(得分:0)
我真的不确定为什么QueryProxy
获得Disease.new
。我已尝试在本地测试您的代码,我得到:
#<Disease uuid: nil, created_at: nil, disease: nil, factor_effect: nil, updated_at: nil>
也许你的代码中有其他东西会影响事物?您可以尝试删除代码,直到它开始工作(虽然这只是在黑暗中刺伤)
WARNING
是因为属性不再支持constraint: :unique
。该选项用于在加载模型时自动创建约束,但它成为维护的噩梦。现在应该使用迁移创建约束。请参阅迁移指南,尤其是this section