Closed SerdarSanri closed 4 months ago
Should be a callback
https://lucid.adonisjs.com/docs/model-factories#relationships
export const UserFactory = Factory.define(User, ({ faker }) => {
return {
username: faker.internet.userName(),
email: faker.internet.email(),
password: faker.internet.password(),
}
})
.relation('posts', () => PostFactory) // 👈
.build()
Package version
18.4.2
Describe the bug
While creating a seeder with factory, any relationship with BelongsTo throws an exception as
this.factory is not a function
. It appears to be thrown in Factory/Relations/Base.js:47 where it tries to run factory as a function yet, factory is an object. Please see the attached screenshot below.Seeder![image](https://github.com/adonisjs/lucid/assets/651202/327ed421-a73f-4680-be4c-8a505c85e7c0)
PatientFactory![image](https://github.com/adonisjs/lucid/assets/651202/667ba0ae-43b1-4d05-83e9-7794c411bc3b)
UserFactory![image](https://github.com/adonisjs/lucid/assets/651202/cb3a5d2b-b024-4896-a722-8b9ebe7b8fcf)
PatientModel![image](https://github.com/adonisjs/lucid/assets/651202/93e5836b-1ee8-4800-9a28-c56e4c794781)
Exception thrown at![image](https://github.com/adonisjs/lucid/assets/651202/1b9e6cc5-6973-47ce-b5bc-18306cb7696f)
node_modules/@adonisjs/lucid/build/src/Factory/Relations/Base.js:47
( https://github.com/adonisjs/lucid/blob/e038c67dd93b750f97240c2de98791e350c0f4bd/src/factories/relations/base.ts#L41 )Reproduction repo
No response