-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add open and closed post counts to project
A project should be able to return the number of open posts as well as the number of closed posts. This update adds two counter caches to the project model: `open_posts_count` and `closed_posts_count`. These new attributes reflect the count of posts matching the statuses of their namesake. The [`test_after_commit`](https://github.com/grosser/test_after_commit) gem is needed, as transactional fixtures are enabled and counter caches are updated in an `after_commit` callback. See [magnusvk/counter_culture#a-note-on-testing](https://github.com/magnusvk /counter_culture#a-note-on-testing) for more info. This will no longer be needed in Rails 5: [rails/rails/pull/18458](rails/rails#18458). To update existing counters, run the following: ```ruby Post.counter_culture_fix_counts # https://github.com/magnusvk/counter_culture#manually-populating-counter- cache-values ``` Resolves #323
- Loading branch information
1 parent
b4dc16f
commit 7222aff
Showing
6 changed files
with
92 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
db/migrate/20160623044025_add_open_and_closed_posts_count_to_projects.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class AddOpenAndClosedPostsCountToProjects < ActiveRecord::Migration | ||
def change | ||
add_column :projects, :open_posts_count, :integer, null: false, default: 0 | ||
add_column :projects, :closed_posts_count, :integer, null: false, default: 0 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters