Lucid: second query after updating

Hi there! I have a strange case with two queries.

// already existing entity
const order = await ...getting
order.someProperty = 'newValue'
await order.save()

// getting the same entity
const theSameOrder = await ...getting
order.someProperty === 'oldValue' // true

But if I will wrap “getting the same entity” by setTimeout with 1ms I will get this entity with updated property. Why? As if there was no commit to the database when was await order.save()

1 Like

Hi @dakiesse. Try put your code to get oldValue before “const order = await …getting”.

Like this:

// getting the same entity
const theSameOrder = await ...getting
order.someProperty === 'oldValue' // true

// already existing entity
const order = await ...getting
order.someProperty = 'newValue'
await order.save()

Hey @dakiesse! :wave:

Seems that you are checking the wrong model.

const theSameOrder = await ...getting
order.someProperty === 'oldValue' // true

Shouldn’t it be theSameOrder.someProperty?