adonisjs / lucid

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

Bulk updateOrCreate always use insert table SQL instruction #1054

Open noobMaster2048 opened 1 month ago

noobMaster2048 commented 1 month ago

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 commented 1 month ago

Hi.