lucid icon indicating copy to clipboard operation
lucid copied to clipboard

`updateOrCreate` doesn't return correct model

Open bran0h opened this issue 1 year ago • 1 comments

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

bran0h avatar Sep 05 '24 07:09 bran0h

Hey @brano-hozza! 👋🏻

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

RomainLanz avatar Oct 02 '24 07:10 RomainLanz

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

thetutlage avatar Nov 15 '24 04:11 thetutlage

Having the same issue

jonhester avatar Mar 18 '25 03:03 jonhester