Method: Sequel::Schema::AlterTableGenerator#drop_foreign_key
- Defined in:
- lib/sequel/database/schema_generator.rb
#drop_foreign_key(name, opts = OPTS) ⇒ Object
Remove a foreign key and the associated column from the table. General options:
- :name
-
The name of the constraint to drop. If not given, uses the same name that would be used by add_foreign_key with the same columns.
NOTE: If you want to drop only the foreign key constraint but keep the column, use the composite key syntax even if it is only one column.
drop_foreign_key(:artist_id) # DROP CONSTRAINT table_artist_id_fkey, DROP COLUMN artist_id
drop_foreign_key([:name]) # DROP CONSTRAINT table_name_fkey
608 609 610 611 612 613 614 615 |
# File 'lib/sequel/database/schema_generator.rb', line 608 def drop_foreign_key(name, opts=OPTS) if !name.is_a?(Array) && opts[:foreign_key_constraint_name] opts = Hash[opts] opts[:name] = opts[:foreign_key_constraint_name] end drop_composite_foreign_key(Array(name), opts) drop_column(name) unless name.is_a?(Array) end |