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

Save does not save nested field as I expected #6162

Closed
t2wu opened this issue Mar 17, 2023 · 4 comments
Closed

Save does not save nested field as I expected #6162

t2wu opened this issue Mar 17, 2023 · 4 comments
Assignees
Labels
type:with reproduction steps with reproduction steps

Comments

@t2wu
Copy link

t2wu commented Mar 17, 2023

GORM Playground Link

go-gorm/playground#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.

@black-06
Copy link
Contributor

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`

@t2wu
Copy link
Author

t2wu commented Mar 18, 2023

Thank you, I missed that.

@t2wu
Copy link
Author

t2wu commented Mar 19, 2023

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

@black-06
Copy link
Contributor

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

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

No branches or pull requests

3 participants