cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Creating a relationship between a node and a relationship

I often come across a modeling situation where I want to create a relationship between a node and a relationship. I understand that it can't be done in Neo4j and furthermore isn't a supported graph modeling concept. So, what modeling patterns address this situation? (By the way, surely I'm not the first to inquire about this topic, but I haven't found a discussion.) See image for a concrete example. I have two codes, one contained in one code list and another contained in another code list. A person (Stuart) asserts that the two codes are equivalent, i.e., that the EQUIVALENT_TO relationship exists.

I suspect that the modeling advice would be something like, "Insert a node in the middle of the EQUIVALENT_TO relationship...". OK. But what are the best practices for labeling the node? Typing the two relationships that replaced the one? Any Cypher query gotchas when implementing the pattern?

6 REPLIES 6

ameyasoft
Graph Maven

One way is:
(Stuart)-[:ASSERTS]->(CodeRD)
(Stuart)-[:ASSERTS]->(CodeCB)
(CodeRD)-[:EQUIVALENT]->(CodeCB)

Stuart compares CodeRD and CodeCB and finds they are equivalent.

Thanks for your response. Unfortunately I don't see how that helps. Stuart asserting the codes doesn't do anything useful, as far as I can tell. The assertion is on the equivalence of the two codes. Think something like two codes for the United States, one "US" and another "USA" with an "EQUIVALENT_TO" relationship between them. I would indicate that Stuart asserts the equivalence. Of course I can just have a property on the relationship for Stuart's identifier, but I want to actually link to his node.

If I understand correctly, the equivalence is based on some property value of CodeRD and CodeCB. After creating the nodes, you want to have a way to create the EQUIVALENT relationship? Let me know.

Sorry. I think my simplified diagram was simplified to the point of being misleading. Let me be more precise. The following three nodes exist in the database (among others):

  • ( :Code { codeValue: 'RD' } )
  • ( :Code { codeValue: 'C8' } )
  • ( :Person { name: 'Stuart' } )

The real-life person named 'Stuart', represented by a node has determined that the two Code nodes are equivalent (i.e., mean the same thing), leading to this:

( :Code { codeValue: 'RD' } ) - [:EQUIVALENT_TO] -> ( :Code { codeValue: 'C8' } )

Hi Jim,

As always, modeling graphs is an art that should be weighted always with the search queries you expect to satisfy.

Is there any complication with:

( :Code { codeValue: 'RD' } ) - [:EQUIVALENT_TO {asserted_by : 'insert-stuart-identifier-here'}] -> ( :Code { codeValue: 'C8' } )

?

You can always have an index on this property so you can mix IndexSeek with relationship filter on subsequents queries.

Bennu

Bennu (and ameyasoft): Thanks for your comments. I'll try out your recommendations over the next month or so.