Database factories V5

This is my source code:

const ProfileFactory = Factory.define(Profile, ({ faker }) => {
  return {
    firstName: faker.name.firstName(),
    lastName: faker.name.lastName(),
    phone: faker.phone.phoneNumber(),
    address: faker.address.city(),
  };
}).build();

export const UserFactory = Factory.define(User, ({ faker }) => {
  return {
    email: faker.internet.email(),
    password: "password",
  };
})
  .relation("profile", ProfileFactory)
  .build();


import { UserFactory } from "database/factories";

await UserFactory.with("profile").create(4);

Error: TypeError: this.factory is not a function\n at HasOne.compile

Any ideas of what the solution to this problem might be?

No worries guys, I have seen my mistakes. It’s working fine now.

In case you want to know. I did this:

export const UserFactory = Factory.define(User, ({ faker }) => {
  return {
    email: faker.internet.email(),
    password: "password",
  };
})
  .relation("profile", ProfileFactory)
  .build();

Instead of this:

export const UserFactory = Factory.define(User, ({ faker }) => {
  return {
    email: faker.internet.email(),
    password: "password",
  };
})
  .relation("profile",()=> ProfileFactory)
  .build();
1 Like