Skip to content

Instantly share code, notes, and snippets.

@davydovanton
Last active December 28, 2015 12:59
Show Gist options
  • Save davydovanton/7504963 to your computer and use it in GitHub Desktop.
Save davydovanton/7504963 to your computer and use it in GitHub Desktop.
List of all table and column in ActiveRecord
ActiveRecord::Base.connection.tables.each do |table_name|
puts "\n" + table_name
ActiveRecord::Base.connection.columns(table_name).each {|c| puts "- " + c.name + ": " + c.type.to_s + " " + c.limit.to_s}
end
User.reflect_on_all_associations.each { |a| puts "#{a.macro} => #{a.name}" }
# has_many => posts
# has_one => avatar
# has_one => posts_filter
# has_many => votes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment