0
class Invitation
  include Neo4j::ActiveNode
  property :email
end

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

So when query

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

If I add new node Invitation.create(email: 'urvishh@gmail.com')

Then run query

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

This is exact issue I am getting

Vishal G
  • 1,521
  • 11
  • 30
  • I think this is duplicated... http://stackoverflow.com/questions/35255540/neo4j-add-update-properties-if-node-exists – Jorge de los Santos Nov 25 '16 at 17:03
  • @JorgedelosSantos if I get the answer in context of rails purely doing it wil wrapper – Vishal G Nov 25 '16 at 17:07
  • Yeah well the issue is the same, neo4j doesn't handle migrations, you don't need to add something over all the nodes. I didn't read the `property`method code, but I'm sure it will do something like: `value.present? value : default_value` – Jorge de los Santos Nov 25 '16 at 17:13
  • @JorgedelosSantos yes I also belive that neo4j doesn't handle migrations , But I have added exact issue why I am thinking of that – Vishal G Nov 25 '16 at 17:21

1 Answers1

1

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

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.

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

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:

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

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.

Jorge de los Santos
  • 4,583
  • 1
  • 17
  • 35
  • what about this https://github.com/neo4jrb/neo4j/wiki/Neo4j-v3-Migrations – Vishal G Nov 25 '16 at 17:22
  • As stated in my answer, you just need to declare the properties in the model, you don't need migrations to add properties to nodes: http://neo4jrb.readthedocs.io/en/7.2.x/Properties.html#undeclared-properties – Jorge de los Santos Nov 25 '16 at 19:34
  • Yes I did the same But the query goes wrong as previous records is not picking up value default: true.............. I have added the situation in the question, Even if I open neo4j web UI then I can not see the new field in the node, I see if brand new object is created – Vishal G Nov 25 '16 at 19:38
  • What about add the property and run: `Model.update_all(:property, default_value)` – Jorge de los Santos Nov 26 '16 at 23:39
  • sorry for delay... Yes update_all I am doing the same thing for now, But it seem like a spoof what do you thing? – Vishal G Dec 03 '16 at 14:39
  • Did you find a better solution? I can expend some time and build a local dev to try it. – Jorge de los Santos Dec 08 '16 at 21:40
  • No Still I didn't get better solution :( – Vishal G Dec 09 '16 at 15:46
  • Downloaded and installedo neo4j, created a sample node with two fields, and then used: `property :another_field, default: "something"` retrieved the user from the database, and the default was coming. So my answer was right. Neo4j 3.0.7, rails 5, ruby 2.3. – Jorge de los Santos Dec 09 '16 at 19:28
  • Try this Modal_name.where(another_field: "something").count, you will get zero results, and before adding this field you should create some nodes..Defualt always comes if we add this in modal for existing records as well, but query does not include these default when making cypher query.......as it happens in realtional databse when we add some field with defaut value , all field will get these values after running migration – Vishal G Dec 11 '16 at 14:28
  • Updated the answer after researching and testing the issue, and confirming that this is a major milestone in the gem. – Jorge de los Santos Dec 11 '16 at 17:46
  • Can you please add the supported neo4j version needed to use these migrations that would be helpful – Vishal G Dec 15 '16 at 20:16
  • 1
    v8.0.0.rc.4 -> https://github.com/neo4jrb/neo4j/issues/1327#issuecomment-266307838 – Jorge de los Santos Dec 15 '16 at 22:50