How to reload a Model after createMany?


I need to get the automatically generated UUID when multiple users was created, because I need you to get your UUID before saving, but I’m having the following error:

TypeError: users.reload is not a function


User migration

  .defaultTo(this.db.raw('uuid_generate_v4()')) // auto generate uuid


const usersData = [
  { name: 'Foo1', password: 'Bar1' },
  { name: 'Foo2', password: 'Bar2' }

const users = await User.createMany(usersData)

await users.reload() // to get auto generated uuid, but getting error
1 Like

I don’t know if it is possible to load all relations of array by one query.
But u can do like this
for (const user of users.rows ) { await user.reload() }


I used this and it worked, thx!

for (const user of users) { await user.reload() }
const usersJSON => user.$attributes)
1 Like

btw, adonis have its own method to convert database output to json.
just try


instead of

1 Like
TypeError: users.toJSON is not a function

I think that function works only on getting from database, so in this case, .map will resolve, thx.