I have created 5 models in my project using ActiveNode
model and using neo4j gem.
There is a model named Disease, defined as:
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
and Factor:
class Factor
include Neo4j::ActiveNode
property :factor, type: String, constraint: :unique
end
I am able to create nodes for Factor easily but for Disease, it gives error with create
function and returns a QueryProxy object with new
method. (As for other models, they are also working just as Factor, properly as expected)
Here are few commands run on console:
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">
So Factor
node is created easily. Although there are couple of warnings and I'd like to know the reason for that.
When I do the same for Disease:
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 []>
Its getting really bad for me and I'm not getting any workaround for this. Please help!!
I'm really not sure why you are getting a QueryProxy
for Disease.new
. I've tried testing your code locally and I get:
#<Disease uuid: nil, created_at: nil, disease: nil, factor_effect: nil, updated_at: nil>
Maybe there is something else in your code that is affecting things? You might try removing code until it starts working (though that's just a stab in the dark)
The WARNING
s are because constraint: :unique
is no longer supported on properties. That option used to create constraints automatically when the model was loaded, but it became a nightmare to maintain. Constraints should now be created with migrations. See the migration guide, especially this section