method
remove_foreign_key
v7.1.3.4 -
Show latest stable
-
0 notes -
Class: SchemaStatements
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0
- 3.0.9
- 3.1.0
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.0 (0)
- 6.1.3.1 (0)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (0)
- 7.1.3.4 (0)
- What's this?
remove_foreign_key(from_table, to_table = nil, **options)
public
Hide source
# File activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb, line 62 def remove_foreign_key(from_table, to_table = nil, **options) return if options.delete(:if_exists) == true && !foreign_key_exists?(from_table, to_table) to_table ||= options[:to_table] options = options.except(:name, :to_table, :validate) foreign_keys = foreign_keys(from_table) fkey = foreign_keys.detect do |fk| table = to_table || begin table = options[:column].to_s.delete_suffix("_id") Base.pluralize_table_names ? table.pluralize : table end table = strip_table_name_prefix_and_suffix(table) fk_to_table = strip_table_name_prefix_and_suffix(fk.to_table) fk_to_table == table && options.all? { |k, v| fk.options[k].to_s == v.to_s } end || raise(ArgumentError, "Table '#{from_table}' has no foreign key for #{to_table || options}") foreign_keys.delete(fkey) alter_table(from_table, foreign_keys) end