Database transaction not working with Lucid relation #1267
-
I am trying to create a user and his auth information. await Database.transaction(async (trx) => {
const uuid = uuidv4()
let user = new User()
user.uuid = uuid
user.nickname = data.nickname
user.roleId = 1
user = user.useTransaction(trx)
await user.save()
const auth = new UserAuth()
auth.fill({
userUuid: '3x', // throw duplicate key error
type: data.auth_type,
identifier: data.identifier,
credential: data.credential,
})
auth.useTransaction(trx)
await auth.save()
}) My The error happened as expected, but the user record didn't rollback. Is there any mistake in my code? Thanks for your help. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 13 replies
-
Just by looking at the code, it should work. Couple of questions?
|
Beta Was this translation helpful? Give feedback.
-
Btw, I find something interesting. When inserted about 5-6 records, it will be rollback. For example, now have 35 I have no idea why it will happen.
|
Beta Was this translation helpful? Give feedback.
-
I have the same issue, I cloned the repo provided by @sunxyw , and the users are insterted, while the user auths are not. postman call insterted users: user auths: db log query:
|
Beta Was this translation helpful? Give feedback.
Just by looking at the code, it should work. Couple of questions?
@adonisjs/lucid
you are using?