GORM Playground Link

https://github.com/go-gorm/playground/pull/580

Description

I test the following on Postgres.

First I create the user with the nested account.

Then I pull the record of the user along with the nested account.

Then I modify the nested account and do an update to the user via Save()

I expect that the nested account to be updated. But it seems that ON CONFLICT DO UPDATE does not set the the relevant field.

Comment From: black-06

Use FullSaveAssociations

DB.Session(&gorm.Session{FullSaveAssociations: true}).Save(&result)

SQL is:

INSERT INTO `accounts`(`user_id`, `number`, `id`)
VALUES (1, "My new account", 1) 
ON CONFLICT ( `id` ) 
DO UPDATE SET 
    `user_id` = `excluded`.`user_id`,
    `number` = `excluded`.`number` 
RETURNING `id`

Comment From: t2wu

Thank you, I missed that.

Comment From: t2wu

Is there any way to customize to save a particular association and not another?

Comment From: black-06

I have no idea. Perhaps saving alone is the easiest way.