简体   繁体   English

Rails Neo4j如何在现有数据库中添加新字段

[英]Rails Neo4j How to add new field in existing database

class Invitation
  include Neo4j::ActiveNode
  property :email
end

This is Neo node Invitation node I can see it in the graph database. 这是Neo节点邀请节点,我可以在图形数据库中看到它。 - If I add some new field in it, for existing nodes it will not reflect in the graph database - If I create a new node I can see it in graph database -如果在其中添加一些新字段,对于现有节点,它将不会反映在图形数据库中-如果创建新节点,则可以在图形数据库中看到它

So the question is if I have to add one field suppose 所以问题是我是否必须添加一个字段

property :valid, type: Boolean, default: true

How can I add this so that I can see it in existing nodes in graph database???, same like we do in active record migrations 如何添加它,以便可以在图形数据库的现有节点中看到它????,就像我们在活动记录迁移中所做的一样

I have added field in Node 我在节点中添加了字段

property :vish, type: Boolean, default: true

So when query 所以当查询

Invitation.where(vish: true).count ==> result 0 Invitation.where(vish: true).count ==>结果0

If I add new node Invitation.create(email: 'urvishh@gmail.com') 如果我添加新节点Invitation.create(电子邮件:'urvishh@gmail.com')

Then run query 然后运行查询

Invitation.where(vish: true).count ==> result 1 Invitation.where(vish: true).count ==>结果1

This is exact issue I am getting 这是我得到的确切问题

The short answer will be No : there is no way to Search for undeclared property values in persisted nodes. 简短的答案是“ 否” :无法在持久节点中搜索未声明的属性值。

Edited: 编辑:

They added a Migration like behaviour for the gem that might fit your current needs. 他们为宝石添加了可能适合您当前需求的类似迁移的行为。

http://neo4jrb.readthedocs.io/en/latest/Migrations.html http://neo4jrb.readthedocs.io/en/latest/Migrations.html

Discovery answer: 发现答案:

Nodes should be considered as documents that stores properties inside them. 节点应被视为在其内部存储属性的文档。 What we are dealing here is with an implementation of the Cypher Query and the Neo4j::ActiveNode that not only ignores the default values for properties. 我们在这里处理的是Cypher Query和Neo4j::ActiveNode ,它不仅忽略属性的默认值。

This could be easily tested: 这很容易测试:

class User
  include Neo4j::ActiveNode

  property :name, type: String
  property :email, type: String, default: 'example@example.com'
end

Then create two nodes: 然后创建两个节点:

User.create(name: 'John', email: 'john@cena.com'
User.create(name: 'John')

We try to search for undeclared property values : 我们尝试搜索未声明的属性

> User.where(title: 'Mr')
=> #<QueryProxy  CYPHER: "MATCH (result_user:`User`) WHERE (result_user.title = {result_user_title})">

We effectively call Cyper and get results, this means that the property declaration in model is not used at all in the Neo4j::ActiveNode#where 我们有效地调用Cyper并获取结果,这意味着Neo4j::ActiveNode#where根本不使用模型中的属性声明。

It means is only used to set and get properties, but ignored by the finders. 这意味着仅用于设置和获取属性,但被发现者忽略。

There might be workarounds, that are actually missing implementations in the Neo4j gem: 可能存在一些变通办法,实际上Neo4j gem中缺少这些实现:

You can search by array of values in the Cyper connector, but is not parsing properly the values: 您可以在Cyper连接器中按值数组搜索,但不能正确解析值:

User.where(another_field: nil).count
CYPHER 39ms MATCH (result_user:`User`) WHERE (result_user.another_field IS NULL) RETURN count(result_user) AS result_user
=> 100
User.where(another_field: ['Something', nil]).count
 CYPHER 12ms MATCH (result_user:`User`) WHERE (result_user.another_field IN {result_user_another_field}) RETURN count(result_user) AS result_user | {:result_user_another_field=>["Something", nil]}
=> 0

As you can see in the last query, nil is passed literally. 如您在上一个查询中看到的, nil是按字nil传递的。 So you can't do this. 所以你不能这样做。

I've opened an Issue in the repository in your behalf, and linked this question in order to get a solution. 我已代表您在资源库中打开了一个问题 ,并链接了该问题以获取解决方案。

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

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