Created
October 30, 2017 13:34
-
-
Save kjosk/7de78d3e877e2dda8d4aa573a75a992c to your computer and use it in GitHub Desktop.
Get all association class_name of all Models in Rails
This file contains hidden or 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! | |
ActiveRecord::Base.descendants.each do |model| | |
model.reflect_on_all_associations.each do |association| | |
begin | |
klass = model.reflect_on_association(association.name).klass | |
p "#{model.name} #{klass.name}" | |
rescue | |
p "error: #{model.name} #{association.name}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment