所以我之前有過這個問題,我在有效的問題下方有一個答案,但我剛剛意識到我提出的查詢沒有按計劃作業。
基本上現在如果它像這樣作業
(if the roleskey contains any of the roles in slice) and (if the tenantID is an empty string) or (if tenantIDKey is equal to tenantID)
但我需要的是
(if the roleskey contains any of the roles in slice) AND (if the tenantID is an empty string OR if tenantIDKey is equal to tenantID)
這是我當前的查詢:
query := bolthold.Where(roleskey).ContainsAny(bolthold.Slice(roles)...).And(tenantIDKey).Eq("").Or(bolthold.Where(tenantIDKey).Eq(tenantID))
有誰知道如何解決這個問題?
uj5u.com熱心網友回復:
您只需要在 OR 條件內移動空虛檢查。
query := bolthold.
Where(roleskey).
ContainsAny(bolthold.Slice(roles)...).
And(
bolthold.
Where(tenantIDKey).
Eq(tenantID).
Or(tenantIDKey).
Eq("")
)
uj5u.com熱心網友回復:
嘗試:
query := bolthold.
Where(tenantIDKey).Eq("").
Or(
bolthold.
Where(tenantIDKey).
Eq(tenantID)
).
And(roleskey).
ContainsAny(bolthold.Slice(roles)...)
或者
query := bolthold.
Where(tenantIDKey).ContainsAny("", tenantID).
And(roleskey).
ContainsAny(bolthold.Slice(roles)...)
或者
query := bolthold.
Where(tenantIDKey).In("", tenantID).
And(roleskey).
ContainsAny(bolthold.Slice(roles)...)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/473029.html
下一篇:如何排除溢位矩陣的坐標
