lundi 11 novembre 2019

ember-cli-mirage loses relationship when models are sideloaded

I've got following models:

// venue.js
export default Model.extend({
  name: DS.attr('string')
});

// web.js
export default Model.extend({
  webname: DS.attr('string'),
  venue: DS.belongsTo('venue', {async: false})
});

and I use the RESTAdapter. I defined my Mirage configuration as following:

// serializers/application.js
import { RestSerializer } from 'ember-cli-mirage';

export default RestSerializer.extend({
});

// config.js
export default function() {
  this.get('/webs', schema => {
    let venue = schema.venues.create({name: 'venue name'});
    let web = schema.webs.create({
      webname: 'web name',
      venue: venue
    });


    return {
      web: web,
      venue: venue
    }
  })
}

This model sideloading is a part of our application, so I have to use it. Anyways as you can see the response is fine here, i.e. it correctly identifies the foreign keys etc:

chrome tools

But when I receive the response I can't access the venue from the web - it's null. The ember inspector confirms that:

enter image description here

Does anyone have any idea of how I can preserve the relationship when I obtain the data?




Aucun commentaire:

Enregistrer un commentaire