Created
May 7, 2014 18:51
-
-
Save bsiegel/45cca322a3d7b49cae6c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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