Module: Foreigner::ConnectionAdapters::Table
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/foreigner/connection_adapters/abstract/schema_definitions.rb
Instance Method Summary collapse
-
#foreign_key(to_table, options = {}) ⇒ Object
Adds a new foreign key to the table.
-
#references_with_foreign_keys(*args) ⇒ Object
Deprecated.
-
#remove_foreign_key(options) ⇒ Object
Remove the given foreign key from the table.
Instance Method Details
#foreign_key(to_table, options = {}) ⇒ Object
Adds a new foreign key to the table. to_table
can be a single Symbol, or an Array of Symbols. See SchemaStatements#add_foreign_key
Examples
Creating a simple foreign key
t.foreign_key(:people)
Defining the column
t.foreign_key(:people, :column => :sender_id)
Creating a named foreign key
t.foreign_key(:people, :column => :sender_id, :name => 'sender_foreign_key')
Defining the column of the to_table
.
t.foreign_key(:people, :column => :sender_id, :primary_key => :person_id)
33 34 35 |
# File 'lib/foreigner/connection_adapters/abstract/schema_definitions.rb', line 33 def foreign_key(to_table, = {}) @base.add_foreign_key(@table_name, to_table, ) end |
#references_with_foreign_keys(*args) ⇒ Object
Deprecated
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/foreigner/connection_adapters/abstract/schema_definitions.rb', line 57 def references_with_foreign_keys(*args) = args. if = .delete(:foreign_key) p ActiveSupport::Deprecation.send(:deprecation_message, caller, ":foreign_key in t.references is deprecated. " \ "Use t.foreign_key instead") end references_without_foreign_keys(*(args.dup << )) end |
#remove_foreign_key(options) ⇒ Object
Remove the given foreign key from the table.
Examples
Remove the suppliers_company_id_fk in the suppliers table.
change_table :suppliers do |t|
t.remove_foreign_key :companies
end
Remove the foreign key named accounts_branch_id_fk in the accounts table.
change_table :accounts do |t|
t.remove_foreign_key :column => :branch_id
end
Remove the foreign key named party_foreign_key in the accounts table.
change_table :accounts do |t|
t.remove_index :name => :party_foreign_key
end
52 53 54 |
# File 'lib/foreigner/connection_adapters/abstract/schema_definitions.rb', line 52 def remove_foreign_key() @base.remove_foreign_key(@table_name, ) end |