aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorTomas D'Stefano <tomasdestefi@gmail.com>2011-05-31 11:43:19 -0300
committerJon Leighton <j@jonathanleighton.com>2011-07-08 22:26:54 +0100
commitea4b94a7bf707d27af44701fa44ef5f916b84e01 (patch)
treeae5ef07b2cccc9f5dc0d8a1c0f453fe4123dd9ff /activerecord/test
parentdfec3737b05d22e6f298bcae0a8948a4b8803ebd (diff)
downloadrails-ea4b94a7bf707d27af44701fa44ef5f916b84e01.tar.gz
rails-ea4b94a7bf707d27af44701fa44ef5f916b84e01.tar.bz2
rails-ea4b94a7bf707d27af44701fa44ef5f916b84e01.zip
Destroy association habtm record before destroying the record itself. Fixes issue #402.
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/habtm_destroy_order_test.rb10
-rw-r--r--activerecord/test/schema/schema.rb2
2 files changed, 12 insertions, 0 deletions
diff --git a/activerecord/test/cases/habtm_destroy_order_test.rb b/activerecord/test/cases/habtm_destroy_order_test.rb
index f2b91d977e..2ce0de360e 100644
--- a/activerecord/test/cases/habtm_destroy_order_test.rb
+++ b/activerecord/test/cases/habtm_destroy_order_test.rb
@@ -16,6 +16,16 @@ class HabtmDestroyOrderTest < ActiveRecord::TestCase
assert !sicp.destroyed?
end
+ test 'should not raise error if have foreign key in the join table' do
+ student = Student.new(:name => "Ben Bitdiddle")
+ lesson = Lesson.new(:name => "SICP")
+ lesson.students << student
+ lesson.save!
+ assert_nothing_raised do
+ student.destroy
+ end
+ end
+
test "not destroying a student with lessons leaves student<=>lesson association intact" do
# test a normal before_destroy doesn't destroy the habtm joins
begin
diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb
index 4fe311b441..fd2ee23dd5 100644
--- a/activerecord/test/schema/schema.rb
+++ b/activerecord/test/schema/schema.rb
@@ -719,6 +719,8 @@ ActiveRecord::Schema.define do
end
execute "ALTER TABLE fk_test_has_fk ADD CONSTRAINT fk_name FOREIGN KEY (#{quote_column_name 'fk_id'}) REFERENCES #{quote_table_name 'fk_test_has_pk'} (#{quote_column_name 'id'})"
+
+ execute "ALTER TABLE lessons_students ADD CONSTRAINT student_id_fk FOREIGN KEY (#{quote_column_name 'student_id'}) REFERENCES #{quote_table_name 'students'} (#{quote_column_name 'id'})"
end
end