My code like this :
public async update(params: any) {
await Database.transaction(async (trx) => {
const data = await Period.findOrFail(params.id, { client: trx })
data.from = params.from
data.to = params.to
data.desc = params.desc
data.useTransaction(trx)
await data.save()
let arrFiles = []
for (let i in params.file_names) {
arrFiles.push({
fileName: Date.now() + '_' + params.file_names[i],
fileUri: params.file_uris[i],
createdBy: params.created_by,
})
}
await period
.related('files')
.updateOrCreateMany(arrFiles, 'fileUrl', { client: trx })
await File.query()
.whereIn('id', params.removed_file_id)
.useTransaction(trx)
.delete()
return { success: true }
})
}
I had trx
in findOrFail
, save
, updateOrCreateMany
,delete
. But if I run the query it's not read return { success: true }
Is there something wrong with adding trx
to the update process?
If I check on the preview tab in the console, itu return empty object, no properties. Whereas the update prosess success. I check in table of database, it success create, delete & update. Should it return { success: true }
How can I solve this problem?
Please help. Thanks
Note : I follow this reference :: https://docs.adonisjs.com/guides/database/transactions