Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-28-2021 04:35 AM
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?
08-28-2021 10:33 AM
One way is:
(Stuart)-[:ASSERTS]->(CodeRD)
(Stuart)-[:ASSERTS]->(CodeCB)
(CodeRD)-[:EQUIVALENT]->(CodeCB)
Stuart compares CodeRD and CodeCB and finds they are equivalent.
08-28-2021 10:45 AM
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.
08-28-2021 10:53 AM
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.
08-28-2021 12:29 PM
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):
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' } )
08-30-2021 04:51 PM
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
08-30-2021 07:30 PM
Bennu (and ameyasoft): Thanks for your comments. I'll try out your recommendations over the next month or so.
All the sessions of the conference are now available online