Cannot select rows created within same transaction


#1

I’m running a large import script with a transaction inside each iteration however it doesn’t work because I cannot select a row inserted earlier within the same transaction. If I remove the transaction it all works fine.

For example:

    let trx = await Database.beginTransaction();
    let tag = await Tag.create({body: "my body", type: "my type"} )
    let tag2 = await Tag.find(tag.id)

    console.log(tag2 )

The variable tag2 will never be populated.

Any advice?


#2

Use

await Tag.query().transacting(trx).where('id', 1).first()