mardi 14 août 2018

ember-cli-mirage factory only includes one child

I have my mirage setup with two models and factories like so

mirage/models/user.js

import { Model, hasMany } from 'ember-cli-mirage';

export default Model.extend({
  posts: hasMany()
});

mirage/models/post.js

import { Model, belongsTo } from 'ember-cli-mirage';

export default Model.extend({
  user: belongsTo()
});

mirage/factory/user.js

import { Factory, faker } from 'ember-cli-mirage';
export default Factory.extend({

  name(i) {
    return `Person ${i}`;
  },

  afterCreate(user, server){
    server.create('post', 10, { user });
  }

});

mirage/factories/post.js

import { Factory, association } from 'ember-cli-mirage';

export default Factory.extend({

  title(i) {
    return `Show ${i}`;
  },

  description(){
    return faker.lorem.paragraph();
  },

  user: association()
});

mirage/serializers/user.js

import { RestSerializer } from 'ember-cli-mirage';

export default RestSerializer.extend({
  include: ['posts']
});

mirage/scenarios/default.js

export default function(server) {
  server.createList('user', 10);
}

In my model hook I make a request to this.get('store').findAll('user') and then I loop over it in my template. The problem I have is that this get request only includes 1 post per user. What I would have expected is to get 10 posts created per user.

What am I missing here?




Aucun commentaire:

Enregistrer un commentaire