Giter Site home page Giter Site logo

Comments (12)

pboling avatar pboling commented on September 2, 2024

👍 I also need to know this.

from neography.

maxdemarzi avatar maxdemarzi commented on September 2, 2024

Not sure what you are asking here actually. You can delete a relationship like so:

new_node1 = @neo.create_node
new_node2 = @neo.create_node
new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2010', "met" => "college"})
@neo.delete_relationship(new_relationship)

new_relationship["end"]  points to the new_node2

You mean to delete all relationships of that node?

START max=node:node_auto_index(name="Max")
MATCH (max)-[r?]->()
DELETE r;

That would do it.

I guess we could add a delete relationships method to do this?

Is that what you are asking or something else?

from neography.

camertron avatar camertron commented on September 2, 2024

Thanks for your response @maxdemarzi. In your example, you build the relationship and then delete it right away. In my case, I don't have a reference to the relationship yet. I need to be able to get a reference to that exact relationship, then pass it to delete_relationship. Here's the workaround we came up with:

relationship_ids = @neo.execute_script("g.v(#{parent_node.neo_id}).outE('#{relationship_name}').inV.filter { ... }.back(2).id")
relationship_ids.each { |rel_id| @neo.delete_relationship(rel_id) }

It would be great if Neography could encapsulate finding relationship ids as above.

from neography.

pboling avatar pboling commented on September 2, 2024

This is my problem as well. I never want to create and then immediately delete a relationship. I create it, lose the reference, and then eons later need to delete it.

from neography.

maxdemarzi avatar maxdemarzi commented on September 2, 2024

Ah ok.

node1_rels = @neo.get_node_relationships(1)
node1_rels.each { |rel_id| @neo.delete_relationship(rel_id) }

You can also get a specific type or direction for the relationships see:

    def get_node_relationships(id, dir = nil, types = nil)
      @node_relationships.get(id, dir, types)
    end

This is in https://github.com/maxdemarzi/neography/blob/master/lib/neography/rest.rb#L166

from neography.

pboling avatar pboling commented on September 2, 2024

Awesome, thanks @maxdemarzi !

from neography.

camertron avatar camertron commented on September 2, 2024

Right, that's pretty much exactly what I pointed to in my original post. The problem with using get_node_relationships, even with the direction and types options, is the number of potential matches returned. I want to get the specific relationship between node1 and node2 - I don't care about any of the other relationships between node1 and other nodes. Here's what I'm envisioning:

rels = @neo.get_node_relationships(node1, node2)  # there may be more than one, eg. multiple types
node1_rels.each { |rel_id| @neo.delete_relationship(rel_id) }

Is it really a problem to just be able to specify two nodes and get back the relationship(s) between them? I mean, create_relationship(node1, node2) creates a relationship between node1 and node2 - why isn't there a complementary function that takes the same arguments to get/delete the same relationship? I admit, I'm pretty new to the graph database world, maybe I'm just misunderstanding the fundamentals.

from neography.

maxdemarzi avatar maxdemarzi commented on September 2, 2024

It would be nice if the REST API did that...

GET http://localhost:7474/db/data/node/362/relationships/363 <-- get em all.
GET http://localhost:7474/db/data/node/362/relationships/363/in <-- get all Incoming.
GET http://localhost:7474/db/data/node/362/relationships/363/all/LIKES&HATES   <-- for example would get both incoming and outgoing likes & hates rels between these two nodes (if any exist).

Maybe we can add it to Neo4j... or we can cheat and fake it with cypher.

from neography.

maxdemarzi avatar maxdemarzi commented on September 2, 2024

Am I losing it or can't we just do this with the traversal part of the REST API?

from neography.

maxdemarzi avatar maxdemarzi commented on September 2, 2024

Ok... so I added the ability to just get the relationships between two nodes.

See fd13a05

These should all be possible now. Try it, and let me know if you find something not working.

rels = @neo.get_node_relationships_to(node1, node2) 
rels = @neo.get_node_relationships_to(node1, node2, "in") 
rels = @neo.get_node_relationships_to(node1, node2, "in", "enemies") 
rels = @neo.get_node_relationships_to(node1, node2, "in", ["friends", "enemies"]) 
rels.each { |rel_id| @neo.delete_relationship(rel_id) }

from neography.

pboling avatar pboling commented on September 2, 2024

Awesome! Thanks @maxdemarzi , I will test this out soon.

from neography.

camertron avatar camertron commented on September 2, 2024

Cool, thanks @maxdemarzi!

from neography.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.