lucid
lucid copied to clipboard
Custom data passed to createMany does not reach blueprint
Hello, I have the following seed and factory:
const countriesArray = await Factory
.model('App/Models/Country')
.createMany(3, [
{
country: 'Afghanistan',
code: 'AF'
},
{
country: 'Aland Islands',
code: 'AX'
},
{
country: 'Albania',
code: 'AL'
}
])
Factory.blueprint('App/Models/Country', (faker, i, data) => {
return {
name: data.country,
code: data.code
}
})
When I run adonis seed the process fails due to the NOT NULL constraints on both columns - data.country and data.code are undefined.
I may have misunderstood, but it it possible that this line should read like this this?
return Promise.all(_.map(_.range(numberOfRows), (index) => this.create(data[index])))
There are couple of issues here.
data is the array you passed to createMany method and not the object. But you can get the object by using the i (index)
Factory.blueprint('App/Models/Country', (faker, i, data) => {
return {
name: data[i].country,
code: data[i].code
}
})
Next, the i variable sent by Factory class is not incremented, which I have fixed in the related commit