Skip to content

Commit e205df5

Browse files
committed
prevent count query from assuming ncit_id is an id column
1 parent 88d80d4 commit e205df5

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

server/app/graphql/resolvers/top_level_therapies.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ class Resolvers::TopLevelTherapies < GraphQL::Schema::Resolver
99
description 'List and filter Therapies from the NCI Thesaurus.'
1010

1111
scope do
12-
Therapy.select('therapies.id, therapies.name, therapies.ncit_id, count(distinct(assertions.id)) as assertion_count, count(distinct(evidence_items.id)) as evidence_count')
13-
.left_outer_joins(:assertions)
14-
.left_outer_joins(:evidence_items)
12+
Therapy.select('therapies.id, therapies.name, max(therapies.ncit_id) as ncit_id, count(distinct(assertions.id)) as assertion_count, count(distinct(evidence_items.id)) as evidence_count')
13+
.left_outer_joins(:assertions, :evidence_items)
1514
.where("evidence_items.status != 'rejected' OR assertions.status != 'rejected'")
1615
.where(deprecated: false)
17-
.group('therapies.id, therapies.name, therapies.ncit_id')
16+
.group('therapies.id, therapies.name')
1817
.having('COUNT(evidence_items.id) > 0 OR COUNT(assertions.id) > 0')
1918
.order('evidence_count DESC', :id)
2019
end

0 commit comments

Comments
 (0)