one query for avis count
This commit is contained in:
parent
5cfb4114ce
commit
a4e813380a
2 changed files with 21 additions and 10 deletions
|
@ -21,4 +21,17 @@ class Expert < ApplicationRecord
|
|||
def self.by_email(email)
|
||||
Expert.eager_load(:user).find_by(users: { email: email })
|
||||
end
|
||||
|
||||
def avis_summary
|
||||
if @avis_summary.present?
|
||||
@avis_summary
|
||||
else
|
||||
query = <<~EOF
|
||||
COUNT(*) FILTER (where answer IS NULL) AS unanswered,
|
||||
COUNT(*) AS total
|
||||
EOF
|
||||
result = avis.select(query)[0]
|
||||
@avis_summary = { unanswered: result.unanswered, total: result.total }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue