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

Model(&user).Update("a",1), if user with association, if user with association,the association will be updated #2278

mohuishou opened this issue Jan 29, 2019 · 1 comment


Copy link

commented Jan 29, 2019

What version of Go are you using (go version)?

go version go1.11 windows/amd64

Which database and its version are you using?


Please provide a complete runnable program to reproduce your issue. IMPORTANT

Need to runnable with GORM's docker compose config or please provides your config.

package main

import (
	_ ""
	_ ""
	_ ""
	_ ""

var db *gorm.DB

func init() {
	var err error
	db, err = gorm.Open("sqlite3", "test.db")
	// db, err = gorm.Open("postgres", "user=gorm password=gorm port=9920 sslmode=disable")
	// db, err = gorm.Open("mysql", "gorm:gorm@tcp(localhost:9910)/gorm?charset=utf8&parseTime=True")
	// db, err = gorm.Open("mssql", "sqlserver://gorm:LoremIpsum86@localhost:9930?database=gorm")
	if err != nil {

type Product struct {
	Code string
	Price uint
	Applications []Application

type Application struct {
	Name string
	ProductID uint

func main() {
		// Migrate the schema

	// Create
	db.Create(&Product{Code: "L1212", Price: 1000})

	// Read
	var product Product
	db.First(&product, 1) // find product with id 1
	product.Applications = []Application{
			Name: "test",
	// Update - update product's price to 2000
	db.Model(&product).Update("Price", 1000)

in Doc

Update single attribute if it is changed
db.Model(&user).Update("name", "hello")


UPDATE products SET price = '1000', updated_at = '2019-01-29 21:58:52'  WHERE products.deleted_at IS NULL


UPDATE products SET price = '1000', updated_at = '2019-01-29 21:58:52'  WHERE products.deleted_at IS NULL
INSERT INTO applications (created_at,updated_at,deleted_at,name,product_id) VALUES ('2019-01-29 21:58:52','2019-01-29 21:58:52',NULL,'test','0')  

This comment has been minimized.

Copy link

commented Jan 29, 2019

I don't confirm that it's just a bug or a feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.