Hello I'm trying to work out how to create complex relationships in Solidity.
In this example a customer will place an order using a function with arguments, however it cannot be for any combination of shops, types, and products, the relationship must already be established.
In a normal relational database the foreign keys would ensure the relationship was good, and I think in Solidity this is the case with mappings, but I'm not sure how this could be applied:
struct ShopName {
string name; // ShopA, ShopB, ShopC
}
// Each shop can have one or more types
struct ShopType {
string type; // market, brick, online
}
// each type can have one or more products
struct Product {
string productCode;
uint unitPrice;
}
struct SalesOrders {
address customer;
uint qty;
string status; // paid, unpaid
}
So I am imagining a transaction something like this:
function placeOrder(string _shopName, string _shopType, string _productCode, uint _qty) {
...
}
In this example the ShopName ShopType and Product must have an established set of related values, and when an order is placed only those related values can be allowed.
But somehow I think I have a got totally lost because I don't know how to think about this problem, let alone how to access the data.
I have seen the example in readthedocs but I am confused about putting this into practice. Can someone give me some direction please?