- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 4.1k
Open
Labels
type:with reproduction stepswith reproduction stepswith reproduction steps
Description
GORM Playground Link
Description
I was under the impression that using a grouped where cond in a query scope, would apply to the query only 1 time.
The results I'm seeing from applying a grouped cond in a query scope such as:
func ScopeSomething(a,b string) func (*gorm.DB) *gorm.DB {
  return func (db *gorm.DB) *gorm.DB {
    return db.Where(
      // would anticipate the following being added to query as ("field_a" = ? OR "field_b" = ?)
      db.Where("field_a", a).Or("field_b", b),
    )
  }
}This generates a query such as:
SELECT * FROM sometable WHERE field_a = ? or field_b = ? AND (field_a = ? OR field_b = ?)The desired behavior can be achieved by doing the following but it doesn't feel as declarative.
func ScopeSomething(a,b string) func (*gorm.DB) *gorm.DB {
  return func (db *gorm.DB) *gorm.DB {
    return db.Where("field_a = ? OR field_b = ?", a, b)
  }
}Metadata
Metadata
Assignees
Labels
type:with reproduction stepswith reproduction stepswith reproduction steps