Context
We’re using the generic chain-style API with CLI-generated field helpers:
gorm.GModel for type-safe queries
generated.Model.Field.Eq(...) / .In(...) etc. for conditions
What we need
A nested condition like:
WHERE user_status = 0 AND ( (tenant_id = ? AND email IN (?)) OR (tenant_id = ?) OR ... )
i.e. one top-level condition and a group of OR’ed sub-conditions (with some sub-conditions being AND’s).
What we tried
With the chain API we only get flat semantics:
.Where(a).Where(b) → AND
.Where(a).Or(b).Or(c) → one flat OR group
There’s no obvious way to express “AND ( branch1 OR branch2 OR branch3 )” without dropping to the clause package and building the inner group manually:
var orBranches []clause.Expression
// ... build branches ...
qu = qu.Where(generated.Model.UserStatus.Eq(0)).Where(clause.Or(orBranches...))
Question
Why does the chain-style API (and the CLI field helpers) not provide a built-in way to express such nested/grouped conditions? It feels inconsistent that we have to use low-level clause.Or / clause.And for a relatively common “AND of ORs” pattern.
Context
We’re using the generic chain-style API with CLI-generated field helpers:
gorm.GModel for type-safe queries
generated.Model.Field.Eq(...) / .In(...) etc. for conditions
What we need
A nested condition like:
i.e. one top-level condition and a group of OR’ed sub-conditions (with some sub-conditions being AND’s).
What we tried
With the chain API we only get flat semantics:
There’s no obvious way to express “AND ( branch1 OR branch2 OR branch3 )” without dropping to the clause package and building the inner group manually:
Question
Why does the chain-style API (and the CLI field helpers) not provide a built-in way to express such nested/grouped conditions? It feels inconsistent that we have to use low-level clause.Or / clause.And for a relatively common “AND of ORs” pattern.