mardi 5 décembre 2017

How to correctly load multiple model on an ember.js view

I have a subview of a product edit route where I want to show the relation to another model (licence). Of course product hasMany licences and licence belongsTo produit. I also have a component to add relations. From what I understand I should load all the data from outside in the model function of the route.

WHen I go to the route from somewhere else in the emberApp, it display the correct relations, however when I go directly to the page, only the first licence is displayed as a relation.

Here is the model :

import Ember from 'ember';

export default Ember.Route.extend({
  model() {
    const produit = this.modelFor('produits.edit')
    return Ember.RSVP.hash({
      allLicences: this.get('store').findAll('licence'),
      produit: produit
    });
  }
});

In both case, access from the app or whith a reload of the app, ember retrieve the product, and the index of licences. In one case he will show only the first licence of the product, in the other all the correct licence with a relation with the product.

WHat am I doing wrong in this route model?




Aucun commentaire:

Enregistrer un commentaire