Last active
December 25, 2015 11:19
-
-
Save bmxpert1/6967951 to your computer and use it in GitHub Desktop.
Foreigner methods to create and remove foreign keys for cross schema use in PostgreSQL
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
ActiveRecord::Migration.class_eval do | |
def add_foreign_key_ignore_prefix(from_table, to_table, options = {}) | |
table_name_prefix = ActiveRecord::Base.table_name_prefix | |
ActiveRecord::Base.table_name_prefix = '' | |
add_foreign_key(from_table, to_table, options) | |
ActiveRecord::Base.table_name_prefix = table_name_prefix | |
end | |
def remove_foreign_key(from_table, options = {}) | |
table_name_prefix = ActiveRecord::Base.table_name_prefix | |
super(from_table.to_s.gsub(/#{table_name_prefix}/, ''), options) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment