Skip to content

Select cannot work with Updates #1368

@cruvie

Description

@cruvie

GORM Playground Link

go-gorm/playground#1

Description

type TestModelStatus int32

const (
	TestModelUnknown TestModelStatus = 0
	TestModelFailed  TestModelStatus = -1
	TestModelStored  TestModelStatus = 2
)

func (x TestModelStatus) Value() (driver.Value, error) {
	return int32(x), nil
}

func (x *TestModelStatus) Scan(value any) error {
	*x = TestModelStatus(value.(int64))
	return nil
}

type TestModel struct {
	Status TestModelStatus `gorm:"column:status;default:0;not null;type:smallint"`
}

func (x *TestModel) TableName() string {
	return "ss.test_model"
}
func TestName(t *testing.T) {
	test_res.PreparePG()
	query_im.SetDefault(kk_pg.GormClient)
	//err := query_im.TestModel.Debug().
	//	Create(&orm_im.TestModel{Status: orm_im.TestModelUnknown})
	find, err := query_im.TestModel.
		Where(query_im.TestModel.Status.Eq(orm_im.TestModelUnknown)).
		Find()
	if err != nil {
		t.Error(err)
	}
	t.Log(find)
	info, err := query_im.TestModel.
		Select(query_im.TestModel.Status).
		Where(query_im.TestModel.Status.Eq(orm_im.TestModelUnknown)).
		Updates(orm_im.TestModel{Status: orm_im.TestModelStored})
	if err != nil {
		t.Error(err)
	}
	t.Log(info.RowsAffected)
}
=== RUN   TestName
    gen_test.go:27: [0x140003fbf60 0x140003fbf68]
    gen_test.go:35: 0
--- PASS: TestName (0.04s)
PASS

because of #1367 I cannot find the gen SQL

gorm.io/gen v0.3.27
gorm.io/gorm v1.30.1
go 1.25
pg 17

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions