neo4jrb / neo4jrb_spatial

Basic integration between Neo4j.rb and Neo4j Spatial
12 stars 12 forks source link

How can update / delete a node from layer ? #19

Open dfabreguette opened 7 years ago

dfabreguette commented 7 years ago

Hi, I'm using your gem to make "withinDistance" spatial queries with rails and neo4jrb gem. Here's my problem, I attached an after_save callback that calls the "add_to_spatial_layer" method to add the node to the layer. The thing is, if I update the node, it re-calls the method to update the index accordingly to the new location of the node and it actually recreates a new index relationship each time I save the node which leads me to many relationships ! (see screenshot) image How can I do make sure to remove old relationship before creating a new one ? Is there something done in this gem to do that ?

dfabreguette commented 7 years ago

For now I'm using this

myNode.match("(a)-[r:RTREE_REFERENCE]-(b)").delete(:r)

It does the job but I'm not sure this is a good practice !

cheerfulstoic commented 7 years ago

I don't use this gem, but I maintain the neo4j gem, and if you are using ActiveNode you can use the unique option on associations or creates_unique in ActiveRel