mardi 17 octobre 2017

Can't get relationships with Ember Mirage

I'm currently writing tests for my App written with EmberJS. I'm using Mirage. I have the two following models:

mirage/models/paperwork.js

export default Model.extend({
paperwork_products: hasMany('paperwork-product', { inverse: 'paperwork' }),

mirage/models/paperwork-product.js

export default Model.extend({
paperwork: belongsTo('paperwork', { inverse: 'paperwork_products' }),

In my scenario, I'm creating my datas like this:

const paperwork = server.create('paperwork');                                                                                   
const paperworkProduct = server.create('paperwork-product', { paperwork });                      
paperwork.paperwork_products.add(paperworkProduct);

My route:

export default ApplicationRoute.extend({
    model(params) {
        return this.store.findRecord('paperwork', params.paperwork_id, { include: 'paperwork_products' }),        
    },
});

The problem is that I can't access paperwork.paperwork_products in my template. It's undefined (other paperwork attributes are here, but not relationship). I already even tried to put a debugger in my mirage/config.js when routes are declared. My paperwork exists, and his "paperwork_products" too. But I can't get paperwork_products data in my template. What am I doing wrong ? I think I must change something in my :

this.get('v1/paperworks/:id');

But I don't know what ... Thanks in advance !




Aucun commentaire:

Enregistrer un commentaire