instance method
foreign_key_exists?
Ruby on Rails 7.0.10
Since v5.2.8.1Signature
foreign_key_exists?(from_table, to_table = nil, **options)
Checks to see if a foreign key exists on a table for a given foreign key definition.
# Checks to see if a foreign key exists. foreign_key_exists?(:accounts, :branches) # Checks to see if a foreign key on a specified column exists. foreign_key_exists?(:accounts, column: :owner_id) # Checks to see if a foreign key with a custom name exists. foreign_key_exists?(:accounts, name: "special_fk_name")
Parameters
-
from_tablereq -
to_tableopt = nil -
optionskeyrest
Source
# File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 1148
def foreign_key_exists?(from_table, to_table = nil, **options)
foreign_key_for(from_table, to_table: to_table, **options).present?
end
Defined in activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb line 1148
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::ConnectionAdapters::SchemaStatements