2017-04-21 23 views
0
class Client 
=begin 
    Clients are individual users 
=end 
    include Neo4j::ActiveNode 
    include Neo4j::UndeclaredProperties 
    include Neo4j::Timestamps # will give model created_at and updated_at timestamps 

    property :bot_client_id 
    property :sms 
    property :telegram_id 
    property :first_name 
    property :last_name 
    property :email 

end 

當我創建一個新的節點,不存在UUID填充:Neo4j的RuntimeError:無會話中定義

client = Client.new 

,當我試圖找到一個創建的客戶端,我得到一個運行時錯誤:

錯誤的
client = Client.find_by(bot_client_id: 'botid') 

詳情:

RuntimeError: No session defined! 
    from /usr/local/rvm/gems/ruby-2.2.1/gems/neo4j-8.0.13/lib/neo4j/active_base.rb:9:in `block in current_session' 
    from /usr/local/rvm/gems/ruby-2.2.1/gems/neo4j-8.0.13/lib/neo4j/active_base.rb:8:in `tap' 
    from /usr/local/rvm/gems/ruby-2.2.1/gems/neo4j-8.0.13/lib/neo4j/active_base.rb:8:in `current_session' 
    from /usr/local/rvm/gems/ruby-2.2.1/gems/neo4j-8.0.13/lib/neo4j/model_schema.rb:35:in `model_constraints' 
    from /usr/local/rvm/gems/ruby-2.2.1/gems/neo4j-8.0.13/lib/neo4j/model_schema.rb:131:in `each_schema_element' 

我有一個def initialize方法,包括:

​​

回答

0

您的建立會話代碼是正確的,雖然我不知道你的意思,它是在一個def initialize。那是在一個類的initialize方法中嗎?如果是這樣,那個班級是否正在初始化(也許把puts放在那裏看)?我建議將安裝程序代碼放在應用程序的一部分中,在其中全部設置爲全局。

我想我回答了uuid不填充here,當然你將不能夠find_by直到對象持久化(通過createsave)的問題。

+0

謝謝。這不是一個rails應用程序,所以不要使用配置文件。 – Angela

+0

我看到了這個,所以我需要使用這個或者代替上面的代碼? #在JRuby或MRI中,使用Neo4j服務器模式。當railtie被包括時,這會自動發生。 Neo4j :: Session.open(:http)並且是:http一個符號,或者應該是具有憑據的grapheneFB URL? – Angela

+0

我使用'save'獲得以下內容: client.save Neo4j :: DeprecatedSchemaDefinitionError:某些模式元素由模型定義(不再支持),但它們不存在於數據庫中。運行以下命令以創建它們: 耙的Neo4j:generate_schema_migration [約束,客戶端,UUID] 然後運行'耙的Neo4j:migrate' – Angela