vendredi 17 mai 2019

Ember - object related item lost on page reload

I have Order and PaymentMethod models in Ember related like so:

order.js

export default DS.Model.extend({
    paymentStatus: DS.attr('number', { defaultValue: 1 }),
    paymentMethod: DS.belongsTo('payment-method'),
})

payment-method.js

export default DS.Model.extend({
    name: DS.attr('string'),
    orderPaymentMethods: DS.hasMany('order')
})

The order is saved to the database - all fine. I then have a route review-order, which obtains the order model (my API is only retuurning order models for the current logged in user)

review-order.js

export default Route.extend({
    model() {
        const order = this.store.findAll('order', { include: 'payment_method' }).then((orders) => {
           return orders.filterBy('paymentStatus', 1).get('lastObject');
       });
       return order;
   }
});

In my review-order template, I am printing out the payment method relationship like so



This works fine when I am navigate (transitioned to) when the order is created - it prints the name of the payment method. However, if I refresh the page, this is lost, and I have no idea why!




Aucun commentaire:

Enregistrer un commentaire