ITADN

How to use OR() to wrap a scope in a generic API?

#7801Openbirdycn 创建于 2026-06-01
type:missing reproduction steps
B
birdycncommented
Old version API: ``` func OrScope(scopes ...func(stmt *gorm.Statement)) func(stmt *gorm.Statement) { return func(stmt *gorm.Statement) { var activeScopes []func(stmt *gorm.Statement) for _, s := range scopes { if s != nil && HasScopeChanged(s) { activeScopes = append(activeScopes, s) } } if len(activeScopes) == 0 { return } stmt.Where(activeScopes[0]) for i := 1; i < len(activeScopes); i++ { stmt.Or(activeScopes[i]) } } ``` After using generic API modification, it failed
0 条评论