findOrCreate with trx

Can we attach findOrCreate with trx

const trx = await Database.beginTransaction();

var x = await X.findOrCreate(
{ a: a },
{ a: a, b: b }
);
Thank

Yes, you can. As you can see in the findOrCreate method definition, you can pass the trx in the third argument.

const instance = Model.findOrCreate({}, {}, trx)

:slight_smile:

2 Likes

Thanks, work fine

Can we pass txt to hooks.

Can we pass “trx” to hooks?

In short, no.