From 948fd8c8faf1016deb23b73eca0dadb6267603cf Mon Sep 17 00:00:00 2001 From: Andy Allan Date: Wed, 6 Sep 2017 17:57:54 +0100 Subject: [PATCH] Use reports_count so that counter_cache works automatically. --- app/models/report.rb | 2 +- app/views/issues/index.html.erb | 4 ++-- ...ssues.rb => 20160822153153_add_reports_count_to_issues.rb} | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) rename db/migrate/{20160822153153_add_report_count_to_issues.rb => 20160822153153_add_reports_count_to_issues.rb} (59%) diff --git a/app/models/report.rb b/app/models/report.rb index fa90cf04e..477b4b182 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -1,4 +1,4 @@ class Report < ActiveRecord::Base - belongs_to :issue + belongs_to :issue, :counter_cache => true belongs_to :user, :class_name => "User", :foreign_key => :reporter_user_id end diff --git a/app/views/issues/index.html.erb b/app/views/issues/index.html.erb index 0eb2108b9..f9f2c28f9 100644 --- a/app/views/issues/index.html.erb +++ b/app/views/issues/index.html.erb @@ -19,7 +19,7 @@ Search for a particular issue(s):
<%= sortable("status") %> - <%= sortable("report_count", "Number of Reports") %> + <%= sortable("reports_count", "Number of Reports") %> <%= sortable("updated_at","Last updated at") %> <%= sortable("updated_by","Last updated by") %> Link to reports @@ -31,7 +31,7 @@ Search for a particular issue(s):
<% @issues.each do |issue| %> <%= issue.status.humanize %> - <%= issue.report_count %> + <%= issue.reports_count %> <%= l(issue.updated_at.to_datetime, :format => :friendly) %> <% if issue.user_updated %> <%= issue.user_updated.display_name %> <% else %> - <% end %> <%= reports_url(issue) %> diff --git a/db/migrate/20160822153153_add_report_count_to_issues.rb b/db/migrate/20160822153153_add_reports_count_to_issues.rb similarity index 59% rename from db/migrate/20160822153153_add_report_count_to_issues.rb rename to db/migrate/20160822153153_add_reports_count_to_issues.rb index 17a1151e7..a7ccd228f 100644 --- a/db/migrate/20160822153153_add_report_count_to_issues.rb +++ b/db/migrate/20160822153153_add_reports_count_to_issues.rb @@ -1,6 +1,6 @@ -class AddReportCountToIssues < ActiveRecord::Migration +class AddReportsCountToIssues < ActiveRecord::Migration def change - add_column :issues, :report_count, :integer, :default => 0 + add_column :issues, :reports_count, :integer, :default => 0 add_foreign_key :issues, :users, :column => :updated_by, :name => "issues_updated_by_fkey", :on_delete => :cascade add_index :issues, :updated_by end -- 2.39.5