1
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

When I create a new node, there is no uuid populated:

client = Client.new

when I try to find a created client, I get a runtime error:

client = Client.find_by(bot_client_id: 'botid')

Details of the error:

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'

I have a def initialize method which includes:

neo4j_adaptor = Neo4j::Core::CypherSession::Adaptors::HTTP.new('http://user:pass@host:7474')
Neo4j::ActiveBase.on_establish_session { Neo4j::Core::CypherSession.new(neo4j_adaptor) }
Satchel
  • 16,414
  • 23
  • 106
  • 192

1 Answers1

0

Your code for establishing the session is right, though I don't know what you mean that it's in a def initialize. Is that in the initialize method of a class? If so, is that class being initialized (maybe put a puts in there to see)? I would suggest putting the setup code instead in some part of your app where everything is being set up globally.

I think I answered the question of the uuid not being populated here and of course you won't be able to find_by until the object is persisted (either through create or save).

Community
  • 1
  • 1
Brian Underwood
  • 10,746
  • 1
  • 22
  • 34
  • Thanks. This is not a rails app so don't use a config file. – Satchel Apr 21 '17 at 13:56
  • I saw this so I need to use this in addition or instead of the code above? # In JRuby or MRI, using Neo4j Server mode. When the railtie is included, this happens automatically. Neo4j::Session.open(:http) and is the :http a symbol as is or should be the grapheneFB URL with credentials? – Satchel Apr 21 '17 at 13:57
  • I used `save` and got the following: client.save Neo4j::DeprecatedSchemaDefinitionError: Some schema elements were defined by the model (which is no longer supported), but they do not exist in the database. Run the following to create them: rake neo4j:generate_schema_migration[constraint,Client,uuid] And then run `rake neo4j:migrate` – Satchel Apr 21 '17 at 14:13
  • You should run the `rake` task that is specified to create the migration to create a constraint and then run `rake neo4j:migrate` – Brian Underwood Apr 21 '17 at 20:55
  • You might also check out the readthedocs site, particularly this section: http://neo4jrb.readthedocs.io/en/8.0.x/UpgradeGuide.html#indexes-and-constraints – Brian Underwood Apr 21 '17 at 20:56