Skip to content

Commit

Permalink
Simplify soft destroy
Browse files Browse the repository at this point in the history
  • Loading branch information
Braden-077 committed Apr 18, 2024
1 parent cd69845 commit 55895d0
Showing 1 changed file with 1 addition and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ def restore!
def cascade_soft_destroy_nullify
associations_to_nullify = has_many_associations.filter { |association| association.options[:dependent] == :nullify }
associations_to_nullify.map do |child_association| # Grab the actual ActiveRecord::Association class
send(child_association.name).map do |child_record| # call for child records ie. send(:users).map
child_record.send("#{self.class.name.underscore}=", nil) # set the parent record to nil ie. organization = nil
child_record.save(validate: false) # save without validating, so we don't raise errors on the nil foreign key, like Rails does!
end
send(child_association.name).delete_all(:nullify) # nullify the child records, like Rails does!
end
end

Expand Down

0 comments on commit 55895d0

Please sign in to comment.