Skip to content

Unexpected behaviour with upsert if model contains related data? #262

@louisl

Description

@louisl

If I just send the actual model data all works well but if the model data you're trying to upsert contains related data the id's for the actual model don't change.

See UPDATE values in logs below.

BarType.upsert(barType)...

With related data in the model.

 strong-remoting:shared-method - upsert - invoke with +0ms [
{
    id: 7,
    name: 'Belhaven',
    barAccountTypeId: 1,
    barAccountType: { id: 2, accountType: 'Independent' } /* related data */
},
  [Function: callback] ]
  loopback:connector:mysql SQL: INSERT INTO `bar_type`(`id`,`name`,`bar_account_type_id`) VALUES(?,?,?) ON DUPLICATE KEY UPDATE `name`=?,`bar_account_type_id`=?, params: [7,"Belhaven",2,"Belhaven",2] +1ms

Without related data in the model.

strong-remoting:shared-method - upsert - invoke with +0ms [ 
{
    id: 7,
    name: 'Belhaven',
    barAccountTypeId: 1
},
  [Function: callback] ]
  loopback:connector:mysql SQL: INSERT INTO `bar_type`(`id`,`name`,`bar_account_type_id`) VALUES(?,?,?) ON DUPLICATE KEY UPDATE `name`=?,`bar_account_type_id`=?, params: [7,"Belhaven",1,"Belhaven",1] +0ms

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions