Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

246
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda