Skip to content

Commit

Permalink
Combine after_save and after_destroy to after_commit
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielJackson-Oslo committed Mar 2, 2024
1 parent b84f71d commit d48c546
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 12 deletions.
8 changes: 1 addition & 7 deletions app/models/space_types_facility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ class SpaceTypesFacility < ApplicationRecord
belongs_to :space_type
belongs_to :facility

after_create do
space_type.reload.spaces.each do |space|
space.reload.aggregate_facility_reviews(facilities: [facility])
end
end

after_destroy do
after_commit do
space_type.reload.spaces.each do |space|
space.reload.aggregate_facility_reviews(facilities: [facility])
end
Expand Down
6 changes: 1 addition & 5 deletions app/models/space_types_relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ class SpaceTypesRelation < ApplicationRecord
belongs_to :space_type
belongs_to :space

after_save do
space.reload.aggregate_facility_reviews(facilities: space_type.facilities)
end

after_destroy do
after_commit do
space.reload.aggregate_facility_reviews(facilities: space_type.facilities)
end
end
Expand Down

0 comments on commit d48c546

Please sign in to comment.