1

To create nodes in Neo4j with the Neo4j.rb gem, for an empty database, you'd first define the model class as seen in the examples here: http://neo4jrb.readthedocs.io/en/7.2.x/ActiveNode.html

Let's say you have a work project with an existing Neo4j database with an existing schema, nodes, & relationships. What would be the "Rubyist" way to generate models from the schema of an existing Neo4j database? The end goal would be to retrieve and edit existing the nodes and relationships using Neo4j.rb.

Grace
  • 33
  • 2

1 Answers1

0

There was a discussion days ago in which I participated:

Rails Neo4j How to add new field in existing database

And the final conclusion was that you don't have to worry about this.

Nodes act as schemaless storages, and the getters for them doesn't work like ActiveRecord, that's why you don't even inherit from the module.

You can create a model for those nodes, include only the properties you want to handle in the class and work with them without having to worry about legacy properties or even schema.rb, because you are actually just pointing to the nodes based on their stored information, like ID, or existent properties.

I recommend you reading both the question and the answers and even the discussion in GitHub to get a better idea of the "problems" that handling legacy nodes, or maintaining them in time carries, and find a way to handle them that fit your project.

Community
  • 1
  • 1
Jorge de los Santos
  • 4,583
  • 1
  • 17
  • 35
  • 1
    This is more or less right, but for a legacy Neo4j database you will probably need to create `uuid` properties so that the gem has something to grab onto (the internal Neo4j IDs aren't great for referencing from other places). Check out the docs for this migration (which will change in version 8.0 of the gem): https://github.com/neo4jrb/neo4j/wiki/Neo4j-v3-Migrations#add_id_property – Brian Underwood Dec 14 '16 at 21:32
  • 1
    Also if you're having trouble feel free to drop by our chat root on Gitter: https://gitter.im/neo4jrb/neo4j – Brian Underwood Dec 14 '16 at 21:33