Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model.merge incorrectly merges undefined data #1066

Closed
adamcikado opened this issue Nov 22, 2024 · 0 comments
Closed

Model.merge incorrectly merges undefined data #1066

adamcikado opened this issue Nov 22, 2024 · 0 comments

Comments

@adamcikado
Copy link
Contributor

adamcikado commented Nov 22, 2024

Package version

21.4.0

Describe the bug

If you try to pass property with undefined value to .merge method, it actually updates the column value. It should skip the column instead.

class User extends BaseModel {
  @column()
  declare id: number
  
  @column()
  declare username: string | null

  @column()
  declare email: string
}

const user = new User().merge({
  username: 'test',
  email: '[email protected]',
})

// you might receive an object from validator or other source, where object has property, but with undefined value
// which is valid type as merge accepts Partial<>, but any column itself can't have undefined value
user.merge({
  username: 'test2',
  email: undefined, // this value will be actually set
})

user.email // undefined

Reproduction repo

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant