英文:
Go boltDB query using bolthold 3 conditions
问题
所以我之前有一个问题,并且在问题下面有一个答案,它是有效的,但我刚刚意识到我提出的查询不按计划工作。
基本上现在它的工作方式是这样的:
(如果roleskey包含slice中的任何角色)并且(如果tenantID是空字符串)或者(如果tenantIDKey等于tenantID)
但我需要的是:
(如果roleskey包含slice中的任何角色)并且(如果tenantID是空字符串或者tenantIDKey等于tenantID)
这是我当前的查询:
query := bolthold.Where(roleskey).ContainsAny(bolthold.Slice(roles)...).And(tenantIDKey).Eq("").Or(bolthold.Where(tenantIDKey).Eq(tenantID))
有人知道如何解决这个问题吗?
英文:
So I had this question before and I had an answer below the question which worked, but I just realized that the query I came out with does not work as planned.
Basically now if it works like this
(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)
But what I need is
(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)
Here is my current query:
query := bolthold.Where(roleskey).ContainsAny(bolthold.Slice(roles)...).And(tenantIDKey).Eq("").Or(bolthold.Where(tenantIDKey).Eq(tenantID))
Does anyone know how to solve this?
答案1
得分: 2
尝试:
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)...)
英文:
Try:
query := bolthold.
Where(tenantIDKey).Eq("").
Or(
bolthold.
Where(tenantIDKey).
Eq(tenantID)
).
And(roleskey).
ContainsAny(bolthold.Slice(roles)...)
Or
query := bolthold.
Where(tenantIDKey).ContainsAny("", tenantID).
And(roleskey).
ContainsAny(bolthold.Slice(roles)...)
Or
query := bolthold.
Where(tenantIDKey).In("", tenantID).
And(roleskey).
ContainsAny(bolthold.Slice(roles)...)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论