2017-07-05 8 views
1

私のプロジェクトでは、ActiveNodeモデルを使用し、neo4j宝石を使用して5つのモデルを作成しました。Neo4jモデルクラスの一貫性のない動作

として定義病という名前のモデルがあります:

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 

私は簡単ファクターのためにノードを作成することができていますが、病気のために、それは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

'constraint::unique'を見つけたドキュメントページやブログ記事はありましたか?私はそれにすべての参照を削除したいと思います –

+0

ええ...私は確かにブログの投稿でそれを見たに違いない。私はもう一度それを見てすぐにリンクを投稿します。 – vish4071

+0

@BrianUnderwood、neo4jのスクリーンキャストの短いシリーズでは、エピソード2(Properties)の中でこの 'constraint'事柄を定義しました。参照:https://youtu.be/2pCSQkHkPC8?t=81 – vish4071

答えて

0

Disease.newの理由でQueryProxyが届いている理由がわかりません。私はローカルであなたのコードをテストしようとしたと私は得る:

#<Disease uuid: nil, created_at: nil, disease: nil, factor_effect: nil, updated_at: nil> 

たぶん物事に影響を与えているあなたのコード内で何か他のものがありますか?コードが正常に動作するまでコードを削除してみることもできます(ただし、暗闇の中で刺すだけです)

WARNINGは、constraint: :uniqueがプロパティでサポートされなくなったためです。そのオプションは、モデルがロードされたときに自動的に制約を作成するために使用されましたが、維持するのは悪夢となりました。これで、移行での制約が作成されるはずです。特に移行ガイドを参照してください。this section

関連する問題