I am working on building an e-commerce site. My models and their associations are as follows-
App.Product = DS.Model.extend({
// variables
name: attr(),
description: attr(),
display_price: attr(),
stock: attr(),
dates: attr(),
// associations
taxons: DS.hasMany('taxon'),
provider: DS.belongsTo('provider', { async: true }),
images: DS.hasMany('image', { async: true }),
variant: hasOne('variant'), //
})
App.Variant = DS.Model.extend({
// variables
isMaster: attr(),
name: attr(),
images: attr(),
// associations
lineItems: DS.hasMany('lineItem'),
product: DS.belongsTo('product')
})
App.LineItem = DS.Model.extend({
// variables
quantity: attr(),
price: attr(),
date: attr(),
meal_type: attr(),
total: attr(),
display_amount: attr(),
// associations
variant: DS.belongsTo('variant'),
cart: DS.belongsTo('cart')
})
I am loading all the product variants by sending an ajax request (using ActiveModelAdapter). Now, for adding the variants in the cart, I have an api end point which accepts variant_id and quantity. This end point responds with the whole Cart containing all the Line Items. When I add the variants from the variant detail view (by clicking ‘add’ button), the variant is added successfully and I show the Cart with the response. Now, for increasing the quantity of the added Line Item, I need to find the variant from the LineItem. To do so, I am doing the following-
lineItem.get('variant')
This does not work. To my understanding, since variant belongsTo LineItem, this should have worked. Please help!