Ignore deleted record when building report
Fix: cortezaproject/corteza-webapp-compose#68
This commit is contained in:
parent
c1de0a5adf
commit
6c3f5f1bbe
@ -53,8 +53,9 @@ func NewRecordReportBuilder(module *types.Module) *recordReportBuilder {
|
||||
var report = squirrel.
|
||||
Select().
|
||||
Column(squirrel.Alias(squirrel.Expr("COUNT(*)"), "count")).
|
||||
From("compose_record").
|
||||
Where("module_id = ?", module.ID)
|
||||
From("compose_record AS r").
|
||||
Where("r.deleted_at IS NULL").
|
||||
Where("r.module_id = ?", module.ID)
|
||||
|
||||
return &recordReportBuilder{
|
||||
parser: ql.NewParser(),
|
||||
@ -88,7 +89,7 @@ func (b *recordReportBuilder) Build(metrics, dimensions, filters string) (sql st
|
||||
|
||||
if !alreadyJoined(i.Value) {
|
||||
b.report = b.report.LeftJoin(fmt.Sprintf(
|
||||
"compose_record_value AS rv_%s ON (rv_%s.record_id = compose_record.id AND rv_%s.name = ? AND rv_%s.deleted_at IS NULL)",
|
||||
"compose_record_value AS rv_%s ON (rv_%s.record_id = r.id AND rv_%s.name = ? AND rv_%s.deleted_at IS NULL)",
|
||||
i.Value, i.Value, i.Value, i.Value,
|
||||
), i.Value)
|
||||
}
|
||||
|
||||
@ -20,10 +20,10 @@ func TestRecordReportBuilder2(t *testing.T) {
|
||||
|
||||
expected := "SELECT (COUNT(*)) AS count, (CAST(max(rv_single1.value) AS DECIMAL(14,2))) AS metric_0, " +
|
||||
"(QUARTER(rv_ref1.value)) AS dimension_0 " +
|
||||
"FROM compose_record " +
|
||||
"LEFT JOIN compose_record_value AS rv_single1 ON (rv_single1.record_id = compose_record.id AND rv_single1.name = ? AND rv_single1.deleted_at IS NULL) " +
|
||||
"LEFT JOIN compose_record_value AS rv_ref1 ON (rv_ref1.record_id = compose_record.id AND rv_ref1.name = ? AND rv_ref1.deleted_at IS NULL) " +
|
||||
"WHERE module_id = ? AND rv_ref1.value = 2 " +
|
||||
"FROM compose_record AS r " +
|
||||
"LEFT JOIN compose_record_value AS rv_single1 ON (rv_single1.record_id = r.id AND rv_single1.name = ? AND rv_single1.deleted_at IS NULL) " +
|
||||
"LEFT JOIN compose_record_value AS rv_ref1 ON (rv_ref1.record_id = r.id AND rv_ref1.name = ? AND rv_ref1.deleted_at IS NULL) " +
|
||||
"WHERE r.deleted_at IS NULL AND r.module_id = ? AND rv_ref1.value = 2 " +
|
||||
"GROUP BY dimension_0 " +
|
||||
"ORDER BY dimension_0"
|
||||
|
||||
|
||||
@ -127,7 +127,8 @@ func (svc record) Report(namespaceID, moduleID uint64, metrics, dimensions, filt
|
||||
return
|
||||
}
|
||||
|
||||
return svc.recordRepo.Report(m, metrics, dimensions, filter)
|
||||
return svc.recordRepo.
|
||||
Report(m, metrics, dimensions, filter)
|
||||
}
|
||||
|
||||
func (svc record) Find(filter types.RecordFilter) (set types.RecordSet, f types.RecordFilter, err error) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user