From ec44763f03b49e8c6e3bff71772ba32863a01306 Mon Sep 17 00:00:00 2001 From: Mohammad El-Abid Date: Thu, 26 May 2011 00:54:51 -0400 Subject: Removes the restriction on primary key when joining in a habtm && test that it was properly removed --- activerecord/lib/active_record/associations.rb | 6 ------ .../associations/builder/has_and_belongs_to_many.rb | 4 ---- activerecord/test/cases/associations/habtm_join_table_test.rb | 9 ++++----- 3 files changed, 4 insertions(+), 15 deletions(-) diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 1c7209e64e..a0a1ff23db 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -76,12 +76,6 @@ module ActiveRecord end end - class HasAndBelongsToManyAssociationWithPrimaryKeyError < ActiveRecordError #:nodoc: - def initialize(reflection) - super("Primary key is not allowed in a has_and_belongs_to_many join table (#{reflection.options[:join_table]}).") - end - end - class HasAndBelongsToManyAssociationForeignKeyNeeded < ActiveRecordError #:nodoc: def initialize(reflection) super("Cannot create self referential has_and_belongs_to_many association on '#{reflection.class_name rescue nil}##{reflection.name rescue nil}'. :association_foreign_key cannot be the same as the :foreign_key.") diff --git a/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb b/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb index 4b48757da7..d7632b2ea9 100644 --- a/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb +++ b/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb @@ -39,10 +39,6 @@ module ActiveRecord::Associations::Builder model.send(:undecorated_table_name, model.to_s), model.send(:undecorated_table_name, reflection.class_name) ) - - if model.connection.supports_primary_key? && (model.connection.primary_key(reflection.options[:join_table]) rescue false) - raise ActiveRecord::HasAndBelongsToManyAssociationWithPrimaryKeyError.new(reflection) - end end # Generates a join table name from two provided table names. diff --git a/activerecord/test/cases/associations/habtm_join_table_test.rb b/activerecord/test/cases/associations/habtm_join_table_test.rb index 745f169ad7..85bb7d57bb 100644 --- a/activerecord/test/cases/associations/habtm_join_table_test.rb +++ b/activerecord/test/cases/associations/habtm_join_table_test.rb @@ -33,12 +33,11 @@ class HabtmJoinTableTest < ActiveRecord::TestCase ActiveRecord::Base.connection.drop_table :my_books_my_readers end - uses_transaction :test_should_raise_exception_when_join_table_has_a_primary_key - def test_should_raise_exception_when_join_table_has_a_primary_key + uses_transaction :test_should_not_raise_exception_when_join_table_has_a_primary_key + def test_should_not_raise_exception_when_join_table_has_a_primary_key if ActiveRecord::Base.connection.supports_primary_key? - assert_raise ActiveRecord::HasAndBelongsToManyAssociationWithPrimaryKeyError do - MyReader.has_and_belongs_to_many :my_books - end + # This test is to confirm that this feature is now gone + assert MyReader.has_and_belongs_to_many(:my_books).is_a?(ActiveRecord::Reflection::AssociationReflection) end end end -- cgit v1.2.3 From ded7e35cb021512124f491c5ee90aa52829f9932 Mon Sep 17 00:00:00 2001 From: Mohammad Typaldos Date: Thu, 26 May 2011 12:17:20 -0700 Subject: Removes a now needless test - via Github --- activerecord/test/cases/associations/habtm_join_table_test.rb | 8 -------- 1 file changed, 8 deletions(-) diff --git a/activerecord/test/cases/associations/habtm_join_table_test.rb b/activerecord/test/cases/associations/habtm_join_table_test.rb index 85bb7d57bb..fe2b82f2c1 100644 --- a/activerecord/test/cases/associations/habtm_join_table_test.rb +++ b/activerecord/test/cases/associations/habtm_join_table_test.rb @@ -32,12 +32,4 @@ class HabtmJoinTableTest < ActiveRecord::TestCase ActiveRecord::Base.connection.drop_table :my_readers ActiveRecord::Base.connection.drop_table :my_books_my_readers end - - uses_transaction :test_should_not_raise_exception_when_join_table_has_a_primary_key - def test_should_not_raise_exception_when_join_table_has_a_primary_key - if ActiveRecord::Base.connection.supports_primary_key? - # This test is to confirm that this feature is now gone - assert MyReader.has_and_belongs_to_many(:my_books).is_a?(ActiveRecord::Reflection::AssociationReflection) - end - end end -- cgit v1.2.3