I basically have 2 Parse classes in my Online Shop: Product and Order. While the user fills his shopping cart, I reflect that in a local array of items (javascript object) with a property for the product (parse class) and another property for the amount that particular product should have in the cart.
If I now save the order to parse (I'm using the self hosted open source version of parse-server), I end up with an order object like this:
{
"_id": "8XK6gbZZvE",
"items": [
{
"amount": 3,
"product": {
"__type": "Pointer",
"className": "Product",
"objectId": "VWOxzFui6R"
}
}
],
"total": 1800,
"status": "pending",
...
}
My problem with that is that I couldn't find a way to query for orders where the result already includes the products.
The only way I currently can think of is to get rid of the amount so that I don't have to nest the product class inside a JS object. And then just add a product multiple times to the array if necessary.
Something like that:
{
"_id": "6j7l5acSB3",
"items": [
{
"__type": "Pointer",
"className": "Product",
"objectId": "VWOxzFui6R"
}
],
"total": 1210,
"status": "processing",
...
}
Which then allows me to include the items in the order query like this query.include('items');
But would there be also a solution how I could use a structure like my first one and still be able to include the products in the order query? It kind of feels "redundant" to have the same product multiple times in an array if the user ordered this product e.g. 2 or 3 times.