Created
March 19, 2015 19:40
-
-
Save liaden/2a09c245b26e7a67b0d3 to your computer and use it in GitHub Desktop.
Look at all tables and find matching columns.
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
def find_column_in_tables(filter) | |
tables = ActiveRecord::Base.connection.tables.map { |tname| tname.singularize.camelize.constantize rescue nil }.compact | |
column_names_by_table = tables.reduce({}) { |hash, table| hash.merge( table.name => table.column_names ) } | |
column_names_by_table.select { |key,value| value.any? { |column_name| column_name =~ filter } } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment