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

updated_at not touched when generating a query via property obtained from Query in transaction of ReadDB() / WriteDB() when using gorm.io/gen #1254

Open
mika-f opened this issue Jan 24, 2025 · 0 comments

Comments

@mika-f
Copy link

mika-f commented Jan 24, 2025

GORM Playground Link

go-gorm/playground#785

Description

Using gorm.io/[email protected], gorm.io/[email protected], updated_at not touched in generated query when build via property obtained from Query in transaction of ReadDB() / WriteDB():

// expected behavior
query.WriteDB().Transaction(func(tx *q.Query) error {
	user := tx.User
        // UPDATE `users` SET `name`=?,`updated_at`=? WHERE `users`.`name` = ? AND `users`.`deleted_at` IS NULL
	user.WithContext(ctx).Where(user.Name.Eq(name)).UpdateSimple(user.Name.Value("test2"))
	return nil
})

// actual behavior
query.WriteDB().Transaction(func(tx *q.Query) error {
	user := tx.User
	// UPDATE `users` SET `name`=? WHERE `users`.`name` = ? AND `users`.`deleted_at` IS NULL
	user.WithContext(ctx).Where(user.Name.Eq(name)).UpdateSimple(user.Name.Value("test2"))
	return nil
})

When using without ReadDB() / WriteDB(), gorm generates expected SQL:

query.Transaction(func(tx *q.Query) error {
	user := tx.User
	// UPDATE `users` SET `name`=?,`updated_at`=? WHERE `users`.`name` = ? AND `users`.`deleted_at` IS NULL
	user.WithContext(ctx).Where(user.Name.Eq(name)).UpdateSimple(user.Name.Value("test2"))
	return nil
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant