From f3e928c9301eca77834cd2ed7c21070d6d5e3795 Mon Sep 17 00:00:00 2001 From: Denis Arh Date: Wed, 2 Jan 2019 16:28:12 +0100 Subject: [PATCH] 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 --- crm/repository/record.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crm/repository/record.go b/crm/repository/record.go index 5abbeec05..dffb9b1ef 100644 --- a/crm/repository/record.go +++ b/crm/repository/record.go @@ -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"))