Friday, 15 July 2011

reification - Neo4j: How to model relationship properties that are nodes? -



reification - Neo4j: How to model relationship properties that are nodes? -

suppose have simple relationship

create (a:company { name:"apple" })-[:buys]->(b:company { name:"beats" })

now want collect metadata on :buys relationship - user created relationship , sources confirm this. create new node , connect other nodes 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 have several questions:

since in cases queries interested in :buys relationship, leave intact , improve performance queries, right? are there other, improve ways model this? what way generate name/id materialized node? is there way cascade deletion of :buys relationship corresponding :buyout node?

for sure can maintain :buys relationship. should first check if next (company)-[:is_buyer]->()<-[:is_seller]-(other) slow regarding requirements. do premature optimization. if relationship needs referenced 'thing' in domain, should refactored node - modelling approach here. you don't need set properties on intermediate node if don't create sense domain perspective no, neo4j not have cascading behaviour. needs implemented on application level.

neo4j reification

No comments:

Post a Comment