1

Suppose I have a simple relationship like

CREATE (a:Company { name:"Apple" })-[:BUYS]->(b:Company { name:"Beats" })

Now I want to collect metadata on the :BUYS relationship - which User created that Relationship and what are the sources that confirm this. For this I create a new node and connect the other nodes to it:

MATCH (a:Company { name:"Apple" }),(b:Company { name:"Beats" }) 
CREATE a-[:IS_BUYER]->(ab:Buyout { name:"Apple-Beats" })<-[:IS_SELLER]-b

MATCH (u:User { name:"Fred" }),(n1:Newspaper { name:"Washington Post" }),
   (n2:Newspaper { name:"Financial Times" }),(ab:Buyout { name:"Apple-Beats" }) 
CREATE u-[:CREATED]->ab<-[:CONFIRMED_BY]-n1,ab-[:CONFIRMED_BY]->n2

Now I have several questions:

  1. Since in most cases queries are only interested in the :BUYS relationship, I leave that intact and get better performance for those queries, right?
  2. Are there other, better ways to model this?
  3. What is a good way to generate the name/ID for the materialized node?
  4. Is there any way to cascade the deletion of the :BUYS relationship to the corresponding :Buyout node?
chiborg
  • 26,978
  • 14
  • 97
  • 115

1 Answers1

0
  1. for sure you can keep the :BUYS relationship. However you should first check if following (company)-[:IS_BUYER]->()<-[:IS_SELLER]-(other) is to slow regarding your requirements. Do do premature optimization.
  2. if a relationship needs to be referenced from another 'thing' in your domain, it should be refactored as a node - so good modelling approach here.
  3. you don't need to set any properties on the intermediate node if they don't make sense from domain perspective
  4. no, Neo4j does not have any cascading behaviour. This needs to be implemented on application level.
Stefan Armbruster
  • 39,465
  • 6
  • 87
  • 97