Skip to content

Error during seed with factory relation - Adonis Js 5 #1321

Answered by dajpes
dajpes asked this question in Help
Discussion options

You must be logged in to vote

Ok, I managed to fix it, to be honest I don't know if this is the best answer but at least it works:

I added a fake uuid generator to the factory:

import { v4 as uuidv4 } from "uuid";

const myUid= uuidv4()
export const TagFactory = Factory
  .define(Tag, ({ faker }) => {
    return {
      name:faker.random.word() + faker.lorem.word() + "" + faker.random.number(99), 
      category_id: myUid,
    }
  })
  .build()




export const CategoryFactory = Factory
  .define(Category, ({ faker }) => {
    return {
      name: faker.company.companyName(),
      uid:myUid
    }
  })
  .relation('tags', () => TagFactory)
  .build()

I also replaced the old seeder with this:

 await CategoryFactory.create

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by dajpes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
1 participant