Last active
October 25, 2018 19:00
-
-
Save briandunn/90b9d2c79a2fba1fa6643cb252d01014 to your computer and use it in GitHub Desktop.
list tables and columns of non-polymorphic foreign keys
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
ApplicationRecord.descendants.flat_map do |c| | |
c.reflect_on_all_associations.select do |a| | |
ActiveRecord::Reflection::BelongsToReflection === a && !a.options[:polymorphic] | |
end | |
end.map do |r| | |
[r.active_record.table_name, r.plural_name, r.options.slice(:optional, :foreign_key)] | |
end.uniq.sort |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also used the
optional
option to determine if the fk column should benot null
.