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
- #add_referential_integrity(table, keypairs) ⇒ Object
- #drop_referential_integrity(table, keys) ⇒ Object
Instance Method Details
#add_referential_integrity(table, keypairs) ⇒ Object
2 3 4 5 6 |
# File 'lib/activerecord/referential_integrity/active_record/connection_adapters/postgresql_adapter.rb', line 2 def add_referential_integrity(table, keypairs) keypairs.each_pair do |foreign_key, foreign_table| execute "ALTER TABLE #{table} ADD CONSTRAINT #{table}_fk_#{foreign_key} FOREIGN KEY (#{foreign_key}) REFERENCES #{foreign_table} (id)" end end |
#drop_referential_integrity(table, keys) ⇒ Object
8 9 10 11 12 |
# File 'lib/activerecord/referential_integrity/active_record/connection_adapters/postgresql_adapter.rb', line 8 def drop_referential_integrity(table, keys) keys.each do |foreign_key| execute "ALTER TABLE #{table} DROP CONSTRAINT IF EXISTS #{table}_fk_#{foreign_key}" end end |