You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
funcScopeSomething(a,bstring) func (*gorm.DB) *gorm.DB {
returnfunc (db*gorm.DB) *gorm.DB {
returndb.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.
funcScopeSomething(a,bstring) func (*gorm.DB) *gorm.DB {
returnfunc (db*gorm.DB) *gorm.DB {
returndb.Where("field_a = ? OR field_b = ?", a, b)
}
}
The text was updated successfully, but these errors were encountered:
Right. I have noticed this issue, too. Is there any pointers to fixing this bug?
Unfortunately, I haven't made the time to dig into it myself yet.
It strikes me as odd that it actually does generate part of the query in the anticipated manner but also appends the redundant call. I suspect that both calls to db.Where are adding conditions independently somehow.
I don't believe this is applicable to the documentation you've linked since we aren't trying to re-use a gorm.DB and group conditions are explicitly listed in the documentation as a feature: https://gorm.io/docs/advanced_query.html#Group-Conditions
GORM Playground Link
go-gorm/playground#754
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:
This generates a query such as:
The desired behavior can be achieved by doing the following but it doesn't feel as declarative.
The text was updated successfully, but these errors were encountered: