neo4j RuntimeError:没有定义会话

时间:2017-04-21 06:05:29

标签: ruby neo4j neo4j.rb

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:

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方法,其中包括:

neo4j_adaptor = Neo4j::Core::CypherSession::Adaptors::HTTP.new('http://user:pass@host:7474')
Neo4j::ActiveBase.on_establish_session { Neo4j::Core::CypherSession.new(neo4j_adaptor) }

1 个答案:

答案 0 :(得分:0)

您建立会话的代码是正确的,但我不知道您在def initialize中的含义。这是在类的initialize方法中吗?如果是这样,那个类是否被初始化(可能会在那里放一个puts)?我建议将设置代码放在应用程序的某些部分,而这些部分都是全局设置的。

我想我回答了uuid未填充here的问题,当然,在对象被持久化之前,您将无法find_by(通过{{1} }或create)。