Skip to content

Instantly share code, notes, and snippets.

@liaden
Created March 19, 2015 19:40
Show Gist options
  • Save liaden/2a09c245b26e7a67b0d3 to your computer and use it in GitHub Desktop.
Save liaden/2a09c245b26e7a67b0d3 to your computer and use it in GitHub Desktop.
Look at all tables and find matching columns.
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