remove_reference(table_name, ref_name, foreign_key: false, polymorphic: false, **options)
public
Removes the reference(s). Also removes a type column if one
exists.
Remove the reference
remove_reference(:products, :user, index: false)
Remove polymorphic reference
remove_reference(:products, :supplier, polymorphic: true)
Remove the reference with a foreign key
remove_reference(:products, :user, foreign_key: true)
# File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 1049
def remove_reference(table_name, ref_name, foreign_key: false, polymorphic: false, **options)
conditional_options = options.slice(:if_exists, :if_not_exists)
if foreign_key
reference_name = Base.pluralize_table_names ? ref_name.to_s.pluralize : ref_name
if foreign_key.is_a?(Hash)
foreign_key_options = foreign_key.merge(conditional_options)
else
foreign_key_options = { to_table: reference_name, **conditional_options }
end
foreign_key_options[:column] ||= "#{ref_name}_id"
remove_foreign_key(table_name, **foreign_key_options)
end
remove_column(table_name, "#{ref_name}_id", **conditional_options)
remove_column(table_name, "#{ref_name}_type", **conditional_options) if polymorphic
end