<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -344,7 +344,7 @@ module ActiveRecord
           callback(:before_add, record)
           yield(record) if block_given?
           @target ||= [] unless loaded?
-          @target &lt;&lt; record
+          @target &lt;&lt; record unless @reflection.options[:uniq] &amp;&amp; @target.include?(record)
           callback(:after_add, record)
           record
         end</diff>
      <filename>activerecord/lib/active_record/associations/association_collection.rb</filename>
    </modified>
    <modified>
      <diff>@@ -299,6 +299,17 @@ class HasAndBelongsToManyAssociationsTest &lt; ActiveRecord::TestCase
     assert_equal 3, projects(:active_record, :reload).developers.size
   end
 
+  def test_uniq_option_prevents_duplicate_push
+    project = projects(:active_record)
+    project.developers &lt;&lt; developers(:jamis)
+    project.developers &lt;&lt; developers(:david)
+    assert_equal 3, project.developers.size
+
+    project.developers &lt;&lt; developers(:david)
+    project.developers &lt;&lt; developers(:jamis)
+    assert_equal 3, project.developers.size
+  end
+
   def test_deleting
     david = Developer.find(1)
     active_record = Project.find(1)</diff>
      <filename>activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>06e4eb49eaabde76e38e4f275619fe2df51f1e0a</id>
    </parent>
  </parents>
  <author>
    <name>Ernie Miller</name>
    <email>ernie@metautonomo.us</email>
  </author>
  <url>http://github.com/rails/rails/commit/7f6e7ba1f7e8735f1c3f30ba125b5432f00d2a70</url>
  <id>7f6e7ba1f7e8735f1c3f30ba125b5432f00d2a70</id>
  <committed-date>2008-08-08T06:19:08-07:00</committed-date>
  <authored-date>2008-08-02T08:47:05-07:00</authored-date>
  <message>Fixed AssociationCollection#&lt;&lt; resulting in unexpected values in @target when :uniq =&gt; true

Signed-off-by: Michael Koziarski &lt;michael@koziarski.com&gt;</message>
  <tree>6ef0f774359e80d8c20dd4fd244edab61bd00cec</tree>
  <committer>
    <name>Michael Koziarski</name>
    <email>michael@koziarski.com</email>
  </committer>
</commit>
