More explicit record query conditions
Wrapping base scope (module, deleted) into parenthasis so that any additional filter can not negate it, adding explicit `json is not null` to prevent weird results
This commit is contained in:
@@ -130,8 +130,7 @@ func (r *record) Find(moduleID uint64, filter string, sort string, page int, per
|
||||
query := squirrel.
|
||||
Select().
|
||||
From("crm_record").
|
||||
Where("module_id = ?", moduleID).
|
||||
Where(squirrel.Eq{"deleted_at": nil})
|
||||
Where("(module_id = ? AND deleted_at IS NULL AND json IS NOT NULL)", moduleID)
|
||||
|
||||
// Parse filters.
|
||||
p := ql.NewParser()
|
||||
@@ -143,7 +142,7 @@ func (r *record) Find(moduleID uint64, filter string, sort string, page int, per
|
||||
}
|
||||
|
||||
// Append filtering to query.
|
||||
query = query.Where(where)
|
||||
query = query.Where(squirrel.And{where})
|
||||
|
||||
// Create count SQL sentences.
|
||||
count := query.Column(squirrel.Alias(squirrel.Expr("COUNT(*)"), "count"))
|
||||
|
||||
Reference in New Issue
Block a user