Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

47
Views
In the mocking library miragejs is there a way to change the id that mirage auto assigns to be called e.g. "product_id", and not "id"?

The following function, makeServer should successfully seed the mirage database such that console.log(server.db.dump()); will return { id: '1', name: 'Test Product' }.

a) is there a way to change the default name of "id" mirage uses for a given model to something else, e.g. "product_id"? (In e.g. postgresQL the id column does not need to be called "id"). b) if there is, is this a bad idea for some reason?

I have read the 'db', 'model', and 'server' sections of the API docs and haven't been able to find this. At the moment I am passing the data around with "product_id" and if I can't alter mirage I will have to alter that in order that it will return product entries that the requests it is intercepting will accept.

import { createServer, Model } from "miragejs";

export function makeServer({ environment = "test" }) {
  return createServer({
    environment,

    models: {
      product: Model,
    },

    seeds(server) {
      server.create("product", { name: "Test Product" });
    },
  });
}
7 months ago ยท Juan Pablo Isaza
Answer question
Find remote jobs