File tree Expand file tree Collapse file tree 3 files changed +5
-2
lines changed Expand file tree Collapse file tree 3 files changed +5
-2
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ class Comment < ApplicationRecord
3
3
belongs_to :post
4
4
5
5
after_save :update_comments_counter
6
+ after_destroy :update_comments_counter
6
7
7
8
def update_comments_counter
8
9
post . update ( comments_counter : post . comments . count )
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ class Like < ApplicationRecord
3
3
belongs_to :post
4
4
5
5
after_save :update_likes_counter
6
+ after_destroy :update_likes_counter
6
7
7
8
validates :author , uniqueness : { scope : :post }
8
9
Original file line number Diff line number Diff line change 1
1
class Post < ApplicationRecord
2
2
belongs_to :author , class_name : 'User' , foreign_key : :author_id
3
- has_many :likes
4
- has_many :comments
3
+ has_many :likes , dependent : :destroy
4
+ has_many :comments , dependent : :destroy
5
5
6
6
after_save :update_posts_counter
7
+ after_destroy :update_posts_counter
7
8
8
9
validates :title , presence : true
9
10
validates :title , length : { maximum : 250 }
You can’t perform that action at this time.
0 commit comments