Class: ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
- Inherits:
-
AbstractAdapter
- Object
- AbstractAdapter
- ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
- Defined in:
- lib/activerecord/referential_integrity/active_record/connection_adapters/postgresql_adapter.rb
Instance Method Summary collapse
Instance Method Details
#add_foreign_key(table, keypairs) ⇒ Object
2 3 4 5 6 7 8 9 10 |
# File 'lib/activerecord/referential_integrity/active_record/connection_adapters/postgresql_adapter.rb', line 2 def add_foreign_key(table, keypairs) keypairs.each_pair do |foreign_key, foreign_table| sql = "ALTER TABLE #{table} " sql << "ADD CONSTRAINT #{table}_fk_#{foreign_key} " sql << "FOREIGN KEY (#{foreign_key}) " sql << "REFERENCES #{foreign_table} (id)" execute sql end end |
#drop_foreign_key(table, keys) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/activerecord/referential_integrity/active_record/connection_adapters/postgresql_adapter.rb', line 12 def drop_foreign_key(table, keys) keys.each do |foreign_key| sql = "ALTER TABLE #{table} " sql << "DROP CONSTRAINT IF EXISTS #{table}_fk_#{foreign_key} " execute sql end end |