Skip to content

Instantly share code, notes, and snippets.

@johnpmitsch
Created October 30, 2019 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnpmitsch/02268da2997fafb46ba3e2f625fd1f37 to your computer and use it in GitHub Desktop.
Save johnpmitsch/02268da2997fafb46ba3e2f625fd1f37 to your computer and use it in GitHub Desktop.
Debug audit assocation issue in rails
# Context: https://bugzilla.redhat.com/show_bug.cgi?id=1613391
# Update activerecord-5.2.1/lib/active_record/associations/has_many_association.rb on line 105 to log which association is causing issues
def delete_records(records, method)
if method == :destroy
begin
records.each(&:destroy!)
rescue => e
logger = Logger.new('/tmp/rails.log')
logger.info(self.owner)
logger.info(records)
raise e
end
update_counter(-records.length) unless reflection.inverse_updates_counter_cache?
else
scope = self.scope.where(reflection.klass.primary_key => records)
update_counter(-delete_count(method, scope))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment