问题
I'm learning Neo4j and currently whiteboarding the scenario i'm thinking of. I have 3 products P1, P2, P3. P1 and P2 are standalone products. P3 is an adapter that helps you connect P1 and P2.
I thought of P1-[connects_to]-P2
, with P3 as a property of the connects_to
relationship, but then how'd I store P3's properties?
if i create all three products as nodes and do P1-[connects_to]-P3
and P2-[connects_to]-P3
, that's not really representative of the domain.
How do i model this in Neo4j?
回答1:
I think you can use a similar model:
(P1)-[:connected_through]->(A:Adapter)<-[:connected_through]-(P2)
(A)-[:type_is]->(P3)
回答2:
you can also store properties on relationships
Why is creating P3 as a node and connecting it to the others not representative of the domain?
connects_to is a really bad non-descriptive relationship-type, find something in your domain that expresses that relationship better.
回答3:
Have P1, P2 and P3 as nodes (since you said all 3 of them are products) and put P3 with a different label that identifies it as a connecting node.
来源:https://stackoverflow.com/questions/37415193/how-to-model-two-nodes-related-through-a-third-node-in-neo4j