From 5a14349baff600af3df5fcd24d423299488fd9e6 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Tue, 13 Oct 2015 11:05:19 +0200 Subject: `:to_table` when adding a fk through `add_reference`. Closes #21563. The `name` argument of `add_references` was both used to generate the column name `_id` and as the target table for the foreign key `name.pluralize`. It's primary purpose is to define the column name. In cases where the `to_table` of the foreign key is different than the column name we should be able to specify it individually. --- .../active_record/connection_adapters/abstract/schema_statements.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb') diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index ccff853987..b69fd75377 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -724,6 +724,10 @@ module ActiveRecord # # add_reference(:products, :supplier, foreign_key: true) # + # ====== Create a supplier_id column and a foreign key to the firms table + # + # add_reference(:products, :supplier, foreign_key: {to_table: :firms}) + # def add_reference(table_name, *args) ReferenceDefinition.new(*args).add_to(update_table_definition(table_name, self)) end -- cgit v1.2.3