简体   繁体   English

使用Neo4j.rb为现有Neo4j数据库创建模型的最佳方法是什么?

[英]What's the best way to create Models using Neo4j.rb for an existing Neo4j database?

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 要使用Neo4j.rb gem在Neo4j中创建节点,对于空数据库,首先要定义模型类,如下面的示例所示: 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. 假设您有一个包含现有模式,节点和关系的现有Neo4j数据库的工作项目。 What would be the "Rubyist" way to generate models from the schema of an existing Neo4j database? 从现有Neo4j数据库的模式生成模型的“Rubyist”方法是什么? The end goal would be to retrieve and edit existing the nodes and relationships using Neo4j.rb. 最终目标是使用Neo4j.rb检索和编辑现有的节点和关系。

There was a discussion days ago in which I participated: 几天前我参加了一次讨论:

Rails Neo4j How to add new field in existing database Rails Neo4j如何在现有数据库中添加新字段

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. 节点充当无模式存储,并且它们的getter不像ActiveRecord那样工作,这就是你甚至不从模块继承的原因。

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. 您可以为这些节点创建模型,仅包含要在类中处理的属性并使用它们而不必担心遗留属性甚至schema.rb,因为您实际上只是根据存储的节点指向节点信息,如ID或现有属性。

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. 我建议你阅读问题和答案,甚至是GitHub中的讨论,以更好地了解处理遗留节点的“问题”,或及时维护它们,并找到一种方法来处理适合您项目的方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM