diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-06-27 15:39:48 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-06-27 15:39:48 -0300 |
commit | b22edc64884723b8d505e78c4b7e5b585e50a9a7 (patch) | |
tree | 5de4b7a66ed39e19c877cb6f505274a87fe6e201 /activerecord/test/cases/associations | |
parent | eb6e3e34d766cd5d75258b1f4617c993f3347741 (diff) | |
parent | 87d1aba3cba0d9b02490784b3090b0e5c94f56df (diff) | |
download | rails-b22edc64884723b8d505e78c4b7e5b585e50a9a7.tar.gz rails-b22edc64884723b8d505e78c4b7e5b585e50a9a7.tar.bz2 rails-b22edc64884723b8d505e78c4b7e5b585e50a9a7.zip |
Merge pull request #12450 from iantropov/master
Fix bug, when ':dependent => :destroy' violates foreign key constraints
Conflicts:
activerecord/CHANGELOG.md
activerecord/lib/active_record/associations/builder/association.rb
activerecord/lib/active_record/associations/builder/has_one.rb
Diffstat (limited to 'activerecord/test/cases/associations')
-rw-r--r-- | activerecord/test/cases/associations/belongs_to_associations_test.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb index d8d8bbf75e..65b6068df4 100644 --- a/activerecord/test/cases/associations/belongs_to_associations_test.rb +++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb @@ -935,3 +935,39 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase assert_equal 1, Column.count end end + +class BelongsToWithForeignKeyTest < ActiveRecord::TestCase + def setup + ActiveRecord::Schema.define do + drop_table :authors, if_exists: true + drop_table :author_addresses, if_exists: true + + create_table :author_addresses do |t| + end + + exec_query <<-eos + create table authors( + id int, + author_address_id int, + name varchar(255), + PRIMARY KEY (id), + FOREIGN KEY (author_address_id) REFERENCES author_addresses(id) + ); + eos + end + end + + def teardown + ActiveRecord::Schema.define do + drop_table :authors, if_exists: true + drop_table :author_addresses, if_exists: true + end + end + + def test_destroy_linked_models + address = AuthorAddress.create! + author = Author.create! id: 1, name: "Author", author_address_id: address.id + + author.destroy! + end +end |