Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

248
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!