diff options
author | Yves Senn <yves.senn@gmail.com> | 2015-10-13 11:05:19 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2015-10-13 11:05:19 +0200 |
commit | 5a14349baff600af3df5fcd24d423299488fd9e6 (patch) | |
tree | e2b3c60f9df8c8bf5fe49ba776bbc4c4725b4339 /activerecord/test | |
parent | 256097cb570fa31ca7b8140009ebd632a430b8cb (diff) | |
download | rails-5a14349baff600af3df5fcd24d423299488fd9e6.tar.gz rails-5a14349baff600af3df5fcd24d423299488fd9e6.tar.bz2 rails-5a14349baff600af3df5fcd24d423299488fd9e6.zip |
`: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 `<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.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/migration/references_foreign_key_test.rb | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/activerecord/test/cases/migration/references_foreign_key_test.rb b/activerecord/test/cases/migration/references_foreign_key_test.rb index 4f0da999d8..84ec657398 100644 --- a/activerecord/test/cases/migration/references_foreign_key_test.rb +++ b/activerecord/test/cases/migration/references_foreign_key_test.rb @@ -53,6 +53,15 @@ module ActiveRecord assert_equal "other_id", fk.primary_key end + test "to_table option can be passed" do + @connection.create_table :testings do |t| + t.references :parent, foreign_key: { to_table: :testing_parents } + end + fks = @connection.foreign_keys("testings") + assert_equal([["testings", "testing_parents", "parent_id"]], + fks.map {|fk| [fk.from_table, fk.to_table, fk.column] }) + end + test "foreign keys cannot be added to polymorphic relations when creating the table" do @connection.create_table :testings do |t| assert_raises(ArgumentError) do |