问题
Context
A business has many Partners. Each partner could offer multiple Services to their customers. Some Partners offer All Services, some offer a few. The business can always sell a Product to that Partner, and which Product can be sold depends on whether the Partner offers a particular Service or not. So business could sell Product A to Partner A offering Service A. They could offer Product B to Partner A if they don't offer Service B.
Question - if Partners, Products, Services are nodes, where should I model the question 'is this Service offered by this Partner?" Another business question would be "Whats my market for Product A?" - which should return all the Partners that don't offer the Service Built with Product A. Should I do:
Partner_OFFERS_Service_BUILT_WITH_Product
(only have Partner_Service relations where Offered=yes). In this case, how would i return the partners that could be sold a product for Service they don't yet offer?Partner_COULD-OFFER_Service_BUILT_WITH_Product
,and have Offered=yes/no as a property on theCOULD_OFFER
relationshipPartner_COULD-OFFER_Service_BUILT_WITH_Product
, and have Offered=yes/no as a property on the nodeService
. EDIT:This wouldn't work as I can't have this property for every partner.- Have 2 different kinds of relationships -
OFFERS
andDOESNT_OFFER
to relate every partner to every service, but then have a mechanism to switch the relationship if adoption changes.
This will be the backend for a Spring Java application. I understand it could be done in multiple ways and trying to understand simplest way to do this from a query and coding perspective.
EDIT Having discussed with users, the requirement just got more complex. What they actually do is something like a table in relational world with following columns (its denormalised with lot of repetitive data:
PartnerName | Service | Offered? |CurrentlyUsing | WeCouldSellThese |
XX | Baking | Yes |Competitor A, B | Product A |
XX | Baking | Yes |Competitor A, B | Product C |
XX | Baking | Yes |Competitor A, B | Product D |
XX | OnlyDough| Yes |Product A | Product C |
XX | Packing | No | | Product E |
Basically, they need to store information what is being used currently, and whether its currently offered by partner or not, they still try to sell them products (Offered Yes or No will both still lead to a market). There is a many-to-many relationship between service and product as well...which means there is a "3node" relationship - A prospect is defined as a particular partner for a particular product for a particular service, I've tried the following model, but not sure how to query Could_Buy and To_Build together, when there would be multiple of these relationships on a single product.
回答1:
The most simplistic design that should work for you is creating following relationships:
Node(Partner) - [OFFERS] -> Node(Service)
Node(Service) - [BUILT_WITH] -> Node(Service)
Example: PartnerA - OFFERS - ServiceA, ProductA - BUILT_WITH - ServiceA, ProductB - BUILT_WITH - ServiceB
Now how to answer your business questions:
Is this Service offered by this Partner?
: This is pretty straight forward. You just need to check if 'OFFERS' relationship exists between a Service and a Partner.What's my market for Product A?
: You can fetch all Services 'BUILT_WITH' Product A. (which is ServiceA). Next, fetch all the Partner nodes for which 'OFFERS' relationship doesn't exist with ServiceA. Pretty sure, a single query can help achieve this result in Neo4j.
来源:https://stackoverflow.com/questions/61299233/graph-modeling-boolean-value-relationship-property-or-node-property-or-none-a