Created
April 24, 2011 21:24
-
-
Save meltzerj/939891 to your computer and use it in GitHub Desktop.
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
| def build_table_aliases(from) | |
| # for the targets | |
| {}.tap do |aliases| | |
| from.map(&:to_s).sort.map(&:to_sym).each_with_index do |plural, t_index| | |
| begin | |
| table = plural._as_class.table_name | |
| rescue NameError => e | |
| raise PolymorphicError, "Could not find a valid class for #{plural.inspect} (tried #{plural.to_s._classify}). If it's namespaced, be sure to specify it as :\"module/#{plural}\" instead." | |
| end | |
| begin | |
| plural._as_class.columns.map(&:name).each_with_index do |field, f_index| | |
| aliases["#{table}.#{field}"] = "t#{t_index}_r#{f_index}" | |
| end | |
| rescue ActiveRecord::StatementInvalid => e | |
| _logger_warn "Looks like your table doesn't exist for #{plural.to_s._classify}.\nError #{e}\nSkipping..." | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment