User can have multiple carts and every cart can have multiple products
{
carts: [
{
id: 1,
title: "my fav cart",
couponCode: 454,
products: [7,8,9]
},
{
id: 2,
title: "my second fav cart",
couponCode: 966,
products: [4,5,6]
}
],
cartItems: [
{
id: "7",
quantiy: 2,
isWeight: false
}
]
}
CartModel = DS.Model.extend({
title: DS.attr("string"),
couponCode: DS.attr("string"),
products: DS.hasMany("cartItem")
});
CartItemModel = DS.Model.extend({
quantity: DS.attr("number"),
isWeight: DS.attr("boolean")
});
let's say I want to display single cart and do this.store.find("cart", 1)
When I update and save a product ember sends PUT request to /cartItems/{productId} and I can't know which cart product belongs to unless I have cartId in every CartItem
I could make products embedded, but then I would have to send the whole cart of ~50-100 items, just to change quantity for one item
How should I implement this in order to have minimal JSON without repetitive fields and maintain the ability to send only one item through network when I want to update quantity or delete item
Aucun commentaire:
Enregistrer un commentaire