<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -60,6 +60,12 @@ module ActiveRecord
     end
   end
 
+  class HasAndBelongsToManyAssociationWithPrimaryKeyError &lt; ActiveRecordError #:nodoc:
+    def initialize(reflection)
+      super(&quot;Primary key is not allowed in a has_and_belongs_to_many join table (#{reflection.options[:join_table]}).&quot;)
+    end
+  end
+
   class HasAndBelongsToManyAssociationForeignKeyNeeded &lt; ActiveRecordError #:nodoc:
     def initialize(reflection)
       super(&quot;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.&quot;)
@@ -1674,16 +1680,19 @@ module ActiveRecord
 
         def create_has_and_belongs_to_many_reflection(association_id, options, &amp;extension)
           options.assert_valid_keys(valid_keys_for_has_and_belongs_to_many_association)
-
           options[:extend] = create_extension_modules(association_id, extension, options[:extend])
 
           reflection = create_reflection(:has_and_belongs_to_many, association_id, options, self)
+          reflection.options[:join_table] ||= join_table_name(undecorated_table_name(self.to_s), undecorated_table_name(reflection.class_name))
 
           if reflection.association_foreign_key == reflection.primary_key_name
             raise HasAndBelongsToManyAssociationForeignKeyNeeded.new(reflection)
           end
 
-          reflection.options[:join_table] ||= join_table_name(undecorated_table_name(self.to_s), undecorated_table_name(reflection.class_name))
+          if connection.supports_primary_key? &amp;&amp;
+             (connection.primary_key(reflection.options[:join_table]) rescue false)
+             raise HasAndBelongsToManyAssociationWithPrimaryKeyError.new(reflection)
+          end
 
           reflection
         end</diff>
      <filename>activerecord/lib/active_record/associations.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,11 +1,6 @@
 module ActiveRecord
   module Associations
     class HasAndBelongsToManyAssociation &lt; AssociationCollection #:nodoc:
-      def initialize(owner, reflection)
-        super
-        @primary_key_list = {}
-      end
-
       def create(attributes = {})
         create_record(attributes) { |record| insert_record(record) }
       end
@@ -22,12 +17,6 @@ module ActiveRecord
         @reflection.reset_column_information
       end
 
-      def has_primary_key?
-        return @has_primary_key unless @has_primary_key.nil?
-        @has_primary_key = (@owner.connection.supports_primary_key? &amp;&amp;
-          @owner.connection.primary_key(@reflection.options[:join_table]))
-      end
-
       protected
         def construct_find_options!(options)
           options[:joins]      = @join_sql
@@ -40,11 +29,6 @@ module ActiveRecord
         end
 
         def insert_record(record, force = true, validate = true)
-          if has_primary_key?
-            raise ActiveRecord::ConfigurationError,
-              &quot;Primary key is not allowed in a has_and_belongs_to_many join table (#{@reflection.options[:join_table]}).&quot;
-          end
-
           if record.new_record?
             if force
               record.save!</diff>
      <filename>activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb</filename>
    </modified>
    <modified>
      <diff>@@ -36,21 +36,9 @@ class HabtmJoinTableTest &lt; ActiveRecord::TestCase
   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
     if ActiveRecord::Base.connection.supports_primary_key?
-      assert_raise ActiveRecord::ConfigurationError do
-        jaime = MyReader.create(:name=&gt;&quot;Jaime&quot;)
-        jaime.my_books &lt;&lt; MyBook.create(:name=&gt;'Great Expectations')
+      assert_raise ActiveRecord::HasAndBelongsToManyAssociationWithPrimaryKeyError do
+        MyReader.has_and_belongs_to_many :my_books
       end
     end
   end
-
-  uses_transaction :test_should_cache_result_of_primary_key_check
-  def test_should_cache_result_of_primary_key_check
-    if ActiveRecord::Base.connection.supports_primary_key?
-      ActiveRecord::Base.connection.stubs(:primary_key).with('my_books_my_readers').returns(false).once
-      weaz = MyReader.create(:name=&gt;'Weaz')
-
-      weaz.my_books &lt;&lt; MyBook.create(:name=&gt;'Great Expectations')
-      weaz.my_books &lt;&lt; MyBook.create(:name=&gt;'Greater Expectations')
-    end
-  end
 end</diff>
      <filename>activerecord/test/cases/associations/habtm_join_table_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,5 @@
 &lt;% (1..4).each do |id| %&gt;
 edge_&lt;%= id %&gt;:
-  id: &lt;%= id %&gt;
   source_id: &lt;%= id %&gt;
   sink_id: &lt;%= id + 1 %&gt;
-&lt;% end %&gt;
\ No newline at end of file
+&lt;% end %&gt;</diff>
      <filename>activerecord/test/fixtures/edges.yml</filename>
    </modified>
    <modified>
      <diff>@@ -160,7 +160,7 @@ ActiveRecord::Schema.define do
     t.integer :access_level, :default =&gt; 1
   end
 
-  create_table :edges, :force =&gt; true do |t|
+  create_table :edges, :force =&gt; true, :id =&gt; false do |t|
     t.column :source_id, :integer, :null =&gt; false
     t.column :sink_id,   :integer, :null =&gt; false
   end</diff>
      <filename>activerecord/test/schema/schema.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>a1df2590744ed126981dfd5b5709ff6fd5dc6476</id>
    </parent>
  </parents>
  <author>
    <name>Emilio Tagua</name>
    <email>miloops@gmail.com</email>
  </author>
  <url>http://github.com/miloops/rails/commit/f041e07392a4e53b089034adb1a7ba4d989f09fa</url>
  <id>f041e07392a4e53b089034adb1a7ba4d989f09fa</id>
  <committed-date>2009-10-20T06:48:19-07:00</committed-date>
  <authored-date>2009-10-20T06:48:19-07:00</authored-date>
  <message>Revert &quot;Revert &quot;Assert primary key does not exist in habtm when the association is defined, instead of doing that everytime a record is inserted.&quot;&quot;

This reverts commit 2b82708b0efb3a3458e8177beab58f0c585788ae.

Conflicts:

	activerecord/lib/active_record/associations.rb
	activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb</message>
  <tree>fd8e40a60e693f250832a93a2947fcf767f9324d</tree>
  <committer>
    <name>Emilio Tagua</name>
    <email>miloops@gmail.com</email>
  </committer>
</commit>
