(Ember 2.14) 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 the component 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 produits.edit.document route's 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
});
}
});
The produits.edit route's model :
export default Ember.Route.extend({
model(params) {
return this.store.findRecord('produit', params.produit_id);
}
licence.js :
import DS from 'ember-data';
export default DS.Model.extend({
name: DS.attr(),
produits: DS.hasMany('produit'),
licenceVersions: DS.hasMany('licence/licence-version')
});
produit model :
import Ember from 'ember';
import DS from 'ember-data';
import { modelAction } from 'ember-custom-actions';
export default DS.Model.extend({
nom: DS.attr(),
resume: DS.attr(),
description: DS.attr(),
description_sec_title: DS.attr(),
illustration: DS.attr(),
isPublished: DS.attr('boolean'),
famille: DS.belongsTo('famille'),
licences: DS.hasMany('licence'),
addLicence: modelAction('licences', {method: 'POST'}),
anyLicence: Ember.computed('licences.[]', function() {
return this.get('licenses').length > 0;
})
});
The produits.edit.documents part of the template rendering the licences from the produit.
{{#each model.produit.licences as |licence|}}
<tr>
<td>{{licence.name}} </td>
<td>{{interface/remove-button deleteElement=(action "removeLicence" licence model.produit model.produit.licences)}}</td>
<td></td>
</tr>
{{/each}}
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?
EDIT : Right now it can work if
- Licences are included in the product(produit) JSON response from the server
OR
- the JSON calls to the API are code 200 instead of 304. In both case, the browser tools are identical. It only works with Firefox. Sometimes, the first test fails (200) but it works at the second (304) and fails to the subsequent reload (304)