<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -711,7 +711,8 @@ module ActiveRecord
 
         configure_dependency_for_has_many(reflection)
 
-        add_multiple_associated_save_callbacks(reflection.name) unless options[:validate] == false
+        add_multiple_associated_validation_callbacks(reflection.name) unless options[:validate] == false
+        add_multiple_associated_save_callbacks(reflection.name)
         add_association_callbacks(reflection.name, reflection.options)
 
         if options[:through]
@@ -801,7 +802,7 @@ module ActiveRecord
           end
           after_save method_name
 
-          add_single_associated_save_callbacks(reflection.name) if options[:validate] == true
+          add_single_associated_validation_callbacks(reflection.name) if options[:validate] == true
           association_accessor_methods(reflection, HasOneAssociation)
           association_constructor_method(:build,  reflection, HasOneAssociation)
           association_constructor_method(:create, reflection, HasOneAssociation)
@@ -940,7 +941,7 @@ module ActiveRecord
           )
         end
 
-        add_single_associated_save_callbacks(reflection.name) if options[:validate] == true
+        add_single_associated_validation_callbacks(reflection.name) if options[:validate] == true
 
         configure_dependency_for_belongs_to(reflection)
       end
@@ -1043,7 +1044,8 @@ module ActiveRecord
       def has_and_belongs_to_many(association_id, options = {}, &amp;extension)
         reflection = create_has_and_belongs_to_many_reflection(association_id, options, &amp;extension)
 
-        add_multiple_associated_save_callbacks(reflection.name) unless options[:validate] == false
+        add_multiple_associated_validation_callbacks(reflection.name) unless options[:validate] == false
+        add_multiple_associated_save_callbacks(reflection.name)
         collection_accessor_methods(reflection, HasAndBelongsToManyAssociation)
 
         # Don't use a before_destroy callback since users' before_destroy
@@ -1163,7 +1165,7 @@ module ActiveRecord
           end
         end
         
-        def add_single_associated_save_callbacks(association_name)
+        def add_single_associated_validation_callbacks(association_name)
           method_name = &quot;validate_associated_records_for_#{association_name}&quot;.to_sym
           define_method(method_name) do
             association = instance_variable_get(&quot;@#{association_name}&quot;)
@@ -1175,7 +1177,7 @@ module ActiveRecord
           validate method_name
         end
         
-        def add_multiple_associated_save_callbacks(association_name)
+        def add_multiple_associated_validation_callbacks(association_name)
           method_name = &quot;validate_associated_records_for_#{association_name}&quot;.to_sym
           ivar = &quot;@#{association_name}&quot;
 
@@ -1196,6 +1198,10 @@ module ActiveRecord
           end
 
           validate method_name
+        end
+
+        def add_multiple_associated_save_callbacks(association_name)
+          ivar = &quot;@#{association_name}&quot;
 
           method_name = &quot;before_save_associated_records_for_#{association_name}&quot;.to_sym
           define_method(method_name) do
@@ -1217,7 +1223,6 @@ module ActiveRecord
             else
               []
             end
-
             records_to_save.each { |record| association.send(:insert_record, record) } unless records_to_save.blank?
 
             # reconstruct the SQL queries now that we know the owner's id</diff>
      <filename>activerecord/lib/active_record/associations.rb</filename>
    </modified>
    <modified>
      <diff>@@ -345,7 +345,7 @@ class HasManyAssociationsTest &lt; ActiveRecord::TestCase
   def test_invalid_adding_with_validate_false
     firm = Firm.find(:first)
     client = Client.new
-    firm.unvalidated_clients_of_firm &lt;&lt; Client.new
+    firm.unvalidated_clients_of_firm &lt;&lt; client
 
     assert firm.valid?
     assert !client.valid?
@@ -353,6 +353,23 @@ class HasManyAssociationsTest &lt; ActiveRecord::TestCase
     assert client.new_record?
   end
 
+  def test_valid_adding_with_validate_false
+    no_of_clients = Client.count
+
+    firm = Firm.find(:first)
+    client = Client.new(&quot;name&quot; =&gt; &quot;Apple&quot;)
+
+    assert firm.valid?
+    assert client.valid?
+    assert client.new_record?
+
+    firm.unvalidated_clients_of_firm &lt;&lt; client
+
+    assert firm.save
+    assert !client.new_record?
+    assert_equal no_of_clients+1, Client.count
+  end
+
   def test_build
     company = companies(:first_firm)
     new_client = assert_no_queries { company.clients_of_firm.build(&quot;name&quot; =&gt; &quot;Another Client&quot;) }</diff>
      <filename>activerecord/test/cases/associations/has_many_associations_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>5ca7d01ecaa5e97f724169c0177027d0d85066da</id>
    </parent>
  </parents>
  <author>
    <name>Jan De Poorter</name>
    <email>jan@defv.be</email>
  </author>
  <url>http://github.com/rails/rails/commit/b2b761166d28c1aba9165da76fba28027171fd2d</url>
  <id>b2b761166d28c1aba9165da76fba28027171fd2d</id>
  <committed-date>2008-06-26T19:02:13-07:00</committed-date>
  <authored-date>2008-06-25T03:42:33-07:00</authored-date>
  <message>Make sure associated has_many/habtm objects get saved even when :validate =&gt; false is used. [#486 state:resolved]

Signed-off-by: Pratik Naik &lt;pratiknaik@gmail.com&gt;</message>
  <tree>c2a6de3d5fcd63286e77e4e95e2e3374cd9c2e83</tree>
  <committer>
    <name>Pratik Naik</name>
    <email>pratiknaik@gmail.com</email>
  </committer>
</commit>
