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

`updateOrCreate` doesn't return correct model #1053

Closed brano-hozza closed 1 week ago

brano-hozza commented 2 months ago

Package version

^21.1.1

Describe the bug

It looks like that in current implementation you are using merge on existing row. Problem is that when the row is nullable and we are trying to pass undefined property (for instance when we don't want to update that property) I would expect that it would return that property in new model as a null, but now it returns undefined.

// Imagine that we have model User with nullable icon property
const newModel = await User.updateOrCreate(
  { id: props.id },
  {
    name: props.name,
    icon: props.icon, // For example this is undefined
  }
)
...
newModel.icon === undefined // It should be null but it's not

Temporary fix for me is to use id of the new model and find the same model but it's exhaustive

Reproduction repo

No response

RomainLanz commented 1 month ago

Hey @brano-hozza! 👋🏻

Are you able to create a failing test and make a PR with it?

thetutlage commented 1 week ago

Closing since no response from the issue reporter and not actionable as well