Hi, I have a question around data modelling where I'm not sure what the terminology would be for what I am looking to achieve.
Let's say I have the following data:
create (basic_tshirt:Product {name: "Basic T-Shirt"}),
(premium_tshirt: Product {name: "Premium T-Shirt"}),
(color:Attribute {name: "Color"}),
(blue:Value {name: "Blue"}),
(red: Value {name: "Red"}),
(green: Value {name: "Green"})
I want to model the relationships so that:
- Each T-Shirt has a relationship to an Attribute with the name "Color" (but there could be products that do not have an Attribute "Color")
- The Premium T-Shirt has the Values Blue and Red
- The Basic T-Shirt has the Values Red and Green
- I don't want to have to create multiple
Value {name: 'Red'}
nodes.
- Theoretically I could create a direct relationship from Product to Value but this breaks if there are more Attributes that have the same Value (e.g.
Attribute: {name: 'BorderColor'}
).
Is there an option 3 at all, and if so, what is this called so I can research this topic?
Hi @henk.tesligte ! Welcome to the community!
With graphs, and Neo4j of course, the model is driven by the use case! So, it really depends on what you want to achieve with this graph, what kind of questions you want to answer. For instance, if you want to know what products share same values for the same attributes, then this model won't be able to do so, as you have already seen; you could try to create a Color node, with the values as its properties, like this:
CREATE (basic_tshirt:Product {name: "Basic T-Shirt"}),
(premium_tshirt:Product {name: "Premium T-Shirt"}),
(blue:Color {name: 'Blue'}),
(red:Color {name: 'Red'}),
(green:Color {name: 'Green'})
CREATE (basic_tshirt)-[:HAS_COLOR]->(red)
CREATE (basic_tshirt)-[:HAS_COLOR]->(green)
CREATE (premium_tshirt)-[:HAS_COLOR]->(blue)
CREATE (premium_tshirt)-[:HAS_COLOR]->(red)
CREATE (premium_tshirt)-[:HAS_BORDERCOLOR]->(red)
Note that in the last line I added another relationship, there you can see that by naming the relationships differently, we can represent different contexts for the nodes interactions! So, take into account the objectives that you want to achieve with the graph, in order to build the model to fulfill it.
Hope this helps! All the best!