Skip to content

Instantly share code, notes, and snippets.

@bsiegel
Created May 7, 2014 18:51
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 bsiegel/45cca322a3d7b49cae6c to your computer and use it in GitHub Desktop.
Save bsiegel/45cca322a3d7b49cae6c to your computer and use it in GitHub Desktop.
Rails.application.eager_load!
associations = {}
ActiveRecord::Base.descendants.each do |model|
next unless model.reflections.present?
model.reflections.keys.each do |r|
assoc = r.to_s.pluralize
next unless assoc.present?
if associations[assoc].present?
associations[assoc] << model.to_s
else
associations[assoc] = [model.to_s]
end
end
end
ActiveRecord::Base.descendants.each do |model|
next unless model.table_name.present?
join_hits = associations.keys & model.column_names
join_hits.each do |h|
puts "Association '#{h}' on the following models conflicts with column '#{model.table_name}'.'#{h}' for model '#{model.to_s}'"
associations[h].each {|a| puts " - #{a}"}
end
if model.column_names.include?(model.table_name)
puts "Table '#{model.table_name}' contains a column with the same name as the table"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment