【问题标题】:neo4j RuntimeError: No session definedneo4j RuntimeError:未定义会话
【发布时间】:2017-04-21 06:05:29
【问题描述】:
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) }

【问题讨论】:

    标签: ruby neo4j neo4j.rb


    【解决方案1】:

    您建立会话的代码是正确的,尽管我不知道您的意思是它在def initialize 中。那是在类的initialize 方法中吗?如果是这样,该类是否正在初始化(可能放一个puts 在那里查看)?我建议将设置代码放在您的应用程序的某个部分,所有内容都在全局设置。

    我想我回答了uuid 未被填充here 的问题,当然,在对象被持久化(通过createsave)之前,您将无法使用find_by

    【讨论】:

    • 谢谢。这不是 Rails 应用,所以不要使用配置文件。
    • 我看到了这个,所以我需要使用它来补充或代替上面的代码? # 在 JRuby 或 MRI 中,使用 Neo4j Server 模式。当包含 railtie 时,这会自动发生。 Neo4j::Session.open(:http) 和 :http 是原样的符号还是应该是带有凭据的 grapheneFB URL?
    • 我使用save得到以下结果:client.save Neo4j::DeprecatedSchemaDefinitionError: Some schema elements are defined by the model (which is no longer support),但它们在数据库中不存在.运行以下命令来创建它们: rake neo4j:generate_schema_migration[constraint,Client,uuid] 然后运行rake neo4j:migrate
    • 您应该运行为创建迁移指定的rake 任务以创建约束,然后运行rake neo4j:migrate
    • 您还可以查看 readthedocs 网站,尤其是本节:neo4jrb.readthedocs.io/en/8.0.x/…
    猜你喜欢
    • 1970-01-01
    • 2015-10-31
    • 2016-07-21
    • 1970-01-01
    • 1970-01-01
    • 2016-10-31
    • 2017-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多