diff --git a/models/helper.go b/models/helper.go index 2868ad0..1f12a85 100644 --- a/models/helper.go +++ b/models/helper.go @@ -21,8 +21,10 @@ func QueryFilterByConceptDefsPlusCohortPairsHelper(sourceId int, mainCohortDefin // Caching of temporary tables: for optimal performance, a temporary table dictionary / cache is updated, keeping a mapping // of existing temporary table names vs underlying subsets of items in filterConceptDefsAndCohortPairs that gave rise to these // tables. - finalSQL := "(SELECT subject_id FROM " + resultsDataSource.Schema + ".cohort WHERE cohort_definition_id=? )" + " as " + finalSetAlias + " " - query := resultsDataSource.Db.Table(finalSQL, mainCohortDefinitionId) + query := resultsDataSource.Db.Table(resultsDataSource.Schema+".cohort as "+finalSetAlias). + Select("*"). + Where("cohort_definition_id=?", mainCohortDefinitionId) + tmpTableName := "" for i, item := range filterConceptDefsAndCohortPairs { tableAlias := fmt.Sprintf("filter_%d", i) diff --git a/tests/models_tests/models_test.go b/tests/models_tests/models_test.go index 3e521c3..76fdce8 100644 --- a/tests/models_tests/models_test.go +++ b/tests/models_tests/models_test.go @@ -790,7 +790,7 @@ func TestRetrieveHistogramDataBySourceIdAndCohortIdAndConceptDefsPlusCohortPairs } // everyone in the largestCohort has the histogramConceptId, but one person has NULL in the value_as_number: if len(data) != largestCohort.CohortSize-1 { - t.Errorf("expected %d histogram data but got %d", largestCohort.CohortSize, len(data)) + t.Errorf("expected %d histogram data but got %d", largestCohort.CohortSize-1, len(data)) } // now filter on the extendedCopyOfSecondLargestCohort