Is it obvious to anyone why my ‘product
’ data is not side-loading? I am seeing separate API requests to /product for each cart-item. My cart-item
model is:
export default Model.extend({
cart: belongsTo('cart'),
product: belongsTo('product', { async: true }),
skuid: attr('string'),
quantity: attr('number'),
personalization: attr(''),
variantCodes: attr(''),
variantData: attr(''),
prices: attr('')
});
An example API payload is:
{
"cart-items": [
{
"cart": "0048f8cc-ef50-11e7-8337-76502ffc62f3",
"id": "ROVE949352B",
"personalization": [],
"prices": {
"price": 74.95,
"totalPrice": 74.95
},
"product": 4464,
"quantity": 1,
"skuid": "ROVE949352B",
"variantCodes": [],
"variantData": []
},
{
"cart": "0048f8cc-ef50-11e7-8337-76502ffc62f3",
"id": "BLK4226",
"personalization": [],
"prices": {
"origprice": 0,
"price": 60,
"totalPrice": 60
},
"product": 4502,
"quantity": 1,
"skuid": "BLK4226",
"variantCodes": [],
"variantData": []
}
],
"products": [
{
"id": 4464,
"images": {
"image": "tristan-irish-watch.jpg",
},
"name": "Watch - Gold Plated Watch",
"prices": {
"price": 74.95
},
"skuid": "ROVE949352B"
},
{
"id": 4502,
"images": {
"image": "BLK4226.jpg",
},
"name": "Serving Bowl",
"prices": {
"origprice": 0,
"price": 60
}
"skuid": "BLK4226"
}
]
}
The relationship works fine, it’s just resulting in separate requests. I tried async: false but ember is complaining that the data is not there:
Assertion Failed: You looked up the 'product' relationship on a 'cart-item' with id ROVE949352B but some of the associated records were not loaded. Either make sure they are all loaded together with the parent record, or specify that the relationship is async
I’ve also tried using “includes” in the route model hook like:
model() {
return this.get('store').findAll('cart-item', { include: 'products' });
}
Any help appreciated!