Skip to content

Commit

Permalink
Verify Records still exist when trying to destroy them
Browse files Browse the repository at this point in the history
With nested elements, we might have orphaned elements with nested elements
or elements with orphaned nested elements.

This change reloads the record in question in order to make sure it is
still there. If not, the reload will return `nil`, and nothing terrible happens.
  • Loading branch information
mamhoff committed May 18, 2018
1 parent 5f15f36 commit 97cea0d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/alchemy/tasks/tidy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def remove_duplicate_folded_pages
def destroy_orphaned_records(records, class_name)
records.each do |record|
log "Destroy orphaned #{class_name}: #{record.inspect}"
record.destroy
record.reload.try(:destroy)
end
end
end
Expand Down

0 comments on commit 97cea0d

Please sign in to comment.