gorm: Error in generation groups queries in scopes
GORM Playground Link
https://github.com/daashuun/playground
Description
I tried to make
SELECT * FROM "test" WHERE a = 1 AND (b = 2 OR c = 3)
but this request
DB.Table("test").Scopes(
func(d *gorm.DB) *gorm.DB {
return d.Where("a = 1")
},
func(d *gorm.DB) *gorm.DB {
return d.Where(d.Or("b = 2").Or("c = 3"))
},
).Rows()
makes sql
SELECT * FROM "test" WHERE a = 1 OR b = 2 OR c = 3 AND (a = 1 OR b = 2 OR c = 3)
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 15 (9 by maintainers)
Can we add such judgments? I didn’t test it, it’s just a possibility, when the DB instance is the same, the expression should have been added in the subquery.
Sorry, I only read your comment and didn’t check the question, I’ll check and get back to you.
It needs to be repaired and you can use this instead: