1

I am having issue using ember-cli-mirage. My instance of mirage is configured to use the RESTSerializer and the EmbeddedRecordsMixin for relationships. I am able to get records with relationship without a problem, however when I save the parent record I get the following error coming from the ember-data code:

RangeError: Maximum call stack size exceeded

Weirdly enough, if I just removed the EmbeddedRecordsMixin everything works fine. Is there some restriction or special thing you need to do use the EmbeddedRecordsMixin with mirage

// models/artist.js
import DS from 'ember-data';

const { attr, hasMany, Model } = DS;

export default Model.extend({
    name: attr('string'),
    genre: attr('string'),
    country: attr('string'),
    bio: attr(),
    albums: hasMany('album', {
        async: false
    }),
    songs: hasMany('song', {
        async: false
    })
});

// serializers/artist.js
import DS from 'ember-data';
const { RESTSerializer } = DS;

export default RESTSerializer.extend(EmbeddedRecordsMixin, {
    attrs: {
        albums: {
            embedded: 'always'
        },
        songs: {
            embedded: 'always'
        }
    }
});

// mirage/models/artist.js
import { Model, hasMany } from 'ember-cli-mirage';

export default Model.extend({
    albums: hasMany(),
    songs: hasMany()
});


// mirage/factories/artist.js
import { Factory, faker } from 'ember-cli-mirage';

export default Factory.extend({
    name() {
        return faker.name.findName();
    },
    genre() {
        return faker.hacker.noun();
    },
    country() {
        return faker.address.country();
    },
    bio() {
        return faker.lorem.sentence();
    },
    afterCreate(artist, server) {
        server.createList('album', 3, { artist });
        server.createList('song', 3, { artist });
    }
});

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

export default RestSerializer.extend({
    embed: true,
    include: ['songs', 'albums']
});
jpoiri
  • 347
  • 1
  • 8

0 Answers0