adonisjs / lucid

AdonisJS SQL ORM. Supports PostgreSQL, MySQL, MSSQL, Redshift, SQLite and many more
https://lucid.adonisjs.com/
MIT License
1.08k stars 195 forks source link

LucidModel: updateOrCreate not return row with default value #1022

Closed ad-momo closed 7 months ago

ad-momo commented 8 months ago

Package version

@adonisjs/lucid 20.3.1

Describe the bug

Hello,

When you call updateOrCreate of LucidModel, the default values are not set.

Reproduction

For model named MyModel:

// in MyModel model migration file
table.integer('my_field').defaultTo(0);
const myModel = await MyModel.updateOrCreate(searchPayload, {})
console.log(myModel.myField) // undefined 👈

Resolution

Maybe replace this part at here:

await row.save()
return row

to this:

return row.save()

Reproduction repo

No response

ad-momo commented 7 months ago

Ok, I found the refresh ~reload~ method is required : https://github.com/adonisjs/lucid/issues/439