Rails Neo4j如何在现有数据库中添加新字段 [英] Rails Neo4j How to add new field in existing database
问题描述
class Invitation
include Neo4j::ActiveNode
property :email
end
这是Neo节点邀请节点,我可以在图形数据库中看到它. -如果我在其中添加一些新字段,则对于现有节点,它将不会反映在图形数据库中 -如果创建一个新节点,则可以在图形数据库中看到它
This is Neo node Invitation node I can see it in the graph database. - 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
所以查询时
Invitation.where(vish: true).count
==>结果0
如果我添加新节点Invitation.create(电子邮件:'urvishh@gmail.com')
If I add new node Invitation.create(email: 'urvishh@gmail.com')
然后运行查询
Invitation.where(vish: true).count
==>结果1
这是我遇到的确切问题
推荐答案
简而言之将是否:无法搜索来查找持久化中未声明的属性值节点.
The short answer will be No: there is no way to Search for undeclared property values in persisted nodes.
已
他们为宝石添加了类似迁移的行为,可能符合您当前的需求.
They added a Migration like behaviour for the gem that might fit your current needs.
http://neo4jrb.readthedocs.io/en/latest/Migrations.html
发现答案:
应该将节点视为在其内部存储属性的文档.我们在这里处理的是Cypher Query和Neo4j::ActiveNode
的实现,它不仅忽略属性的默认值.
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.
这很容易测试:
class User
include Neo4j::ActiveNode
property :name, type: String
property :email, type: String, default: 'example@example.com'
end
然后创建两个节点:
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})">
我们有效地调用Cyper
并获取结果,这意味着Neo4j::ActiveNode#where
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
这意味着仅用于设置和获取属性,但被发现者忽略.
It means is only used to set and get properties, but ignored by the finders.
可能存在变通办法,实际上Neo4j gem中缺少这些实现:
There might be workarounds, that are actually missing implementations in the Neo4j gem:
您可以在Cyper连接器中按值数组搜索,但不能正确解析这些值:
You can search by array of values in the Cyper connector, but is not parsing properly the values:
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
正如您在上一个查询中看到的那样,nil
是按字面传递的.所以你不能这样做.
As you can see in the last query, nil
is passed literally. 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.
这篇关于Rails Neo4j如何在现有数据库中添加新字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!