Created
January 9, 2018 14:03
-
-
Save dira/2a061cd6ede046c6994fc767e70273c3 to your computer and use it in GitHub Desktop.
Rails - use reflection to get all declared ActiveRecord associations between entities
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! | |
data = ActiveRecord::Base.descendants.map{|klass| [klass, klass.reflections.map{|k, v| [v.class.name, k]}] } | |
data.map{|klass, relations| relations.map{|k, v| "#{klass} #{k.gsub('ActiveRecord::Reflection::', '').gsub('Reflection', '').underscore.humanize.downcase} #{v}"} }.flatten | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment