Skip to content

Commit 03c4dcb

Browse files
committed
#3d8979n - renaming alias and formatting the chats_count_aggregation query
1 parent ad24db7 commit 03c4dcb

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

app/models/application.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ def self.aggregate_chats_count
2323
# Their might be an ActiveRecord-based approach but I couldn't find any.
2424
self.connection.execute(
2525
'UPDATE applications apps
26-
JOIN(SELECT application_id, COUNT(application_id) as aggregation
27-
FROM chats
28-
GROUP BY application_id) c ON apps.id = c.application_id
29-
SET apps.chats_count = c.aggregation;'
26+
JOIN(
27+
SELECT application_id, COUNT(application_id) as aggregation
28+
FROM chats
29+
GROUP BY application_id
30+
) chats ON apps.id = chats.application_id
31+
SET apps.chats_count = chats.aggregation;'
3032
)
3133
end
3234
end

0 commit comments

Comments
 (0)