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

Bulk updateOrCreate always use insert table SQL instruction #1054

Open
noobMaster2048 opened this issue Oct 7, 2024 · 1 comment
Open

Bulk updateOrCreate always use insert table SQL instruction #1054

noobMaster2048 opened this issue Oct 7, 2024 · 1 comment

Comments

@noobMaster2048
Copy link

Package version

21.2.0

Describe the bug

When updating a parent model with its children, the updateOrCreateMany method executes an insert table instruction instead of an update.

`export default class Product extends BaseModel {

  @hasMany(() => ProductPrice)
   declare prices: HasMany<typeof ProductPrice>

}`

`export default class ProductPrice extends BaseModel {

@column()
declare productKey: string | undefined

@belongsTo(() => Product)
declare product: BelongsTo<typeof Product>

}`

`const record = await Product.findOrFail(params.key)
await record.merge(payload).save()
await record.related('prices').updateOrCreateMany(payload.prices, 'price')

`
image

Reproduction repo

No response

@thetutlage
Copy link
Member

Hi.

  • Can you please format the source code properly?
  • Can you please share that is already in the database?
  • What exact data are you passing to the updateOrCreateMany method?
  • What is expected outcome and what is the actual outcome?

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

No branches or pull requests

2 participants