Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

247
Visualizações
Mirage.js hasMany() relationship models get wrapped in an array

I'm mocking our server responses with Mirage.js for testing purposes. I've encountered the following problem.

I have an event model which has a hasMany() relationship to the image model, like so:

// server.ts

createServer({
    models: {
      event: Model.extend({
        images: hasMany(),
      }),
      image: Model.extend({
        event: belongsTo(),
      }),
    }

    ...
})

and an event factory which populates the images in afterCreate

// eventFactory.ts

Factory.extend<FactoryType<Partial<Event>>>({
  ...

  /* event relationships */
  afterCreate(event, server) {
    event.update({
      images: server.createList('image', 3),
    });
  },
})

but the response is a collection instead of an array and I cannot access the images directly via event.images[0] as they get wrapped in a models array like so event.images.models[0]

response

How do I get the server to include the images directly, so I can access them via event.images[0]? Am I missing something, or can this be achieved by using a serializer of some sort? Thanks!

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda