v5.0.0.1 - Show latest stable - 0 notes - Class: ActiveRecord::ConnectionAdapters::SchemaStatements
foreign_key_exists?(from_table, options_or_to_table = {}) public

Checks to see if a foreign key exists on a table for a given foreign key definition.

# Check a foreign key exists
foreign_key_exists?(:accounts, :branches)

# Check a foreign key on a specified column exists
foreign_key_exists?(:accounts, column: :owner_id)

# Check a foreign key with a custom name exists
foreign_key_exists?(:accounts, name: "special_fk_name")
Show source
Register or log in to add new notes.