Skip to content
This repository
Browse code

Alias association #build to #new so it behaves predictably. Closes #8787

.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7913 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 671228942d1a49f223739f249728eebbc590f66e 1 parent 3334636
Jeremy Kemper authored October 15, 2007
2  activerecord/CHANGELOG
... ...
@@ -1,5 +1,7 @@
1 1
 *SVN*
2 2
 
  3
+* Alias association #build to #new so it behaves predictably.  #8787 [lifofifo]
  4
+
3 5
 * Add notes to documentation regarding attr_readonly behavior with counter caches and polymorphic associations.  Closes #9835 [saimonmoore, rick]
4 6
 
5 7
 * Observers can observe model names as symbols properly now.  Closes #9869  [queso]
1  activerecord/lib/active_record/associations/has_many_through_association.rb
@@ -88,6 +88,7 @@ def delete(*records)
88 88
       def build(attrs = nil)
89 89
         raise ActiveRecord::HasManyThroughCantAssociateNewRecords.new(@owner, @reflection.through_reflection)
90 90
       end
  91
+      alias_method :new, :build
91 92
 
92 93
       def create!(attrs = nil)
93 94
         @reflection.klass.transaction do
1  activerecord/test/associations/join_model_test.rb
@@ -417,6 +417,7 @@ def test_raise_error_when_adding_new_record_to_has_many_through
417 417
     assert_raise(ActiveRecord::HasManyThroughCantAssociateNewRecords) { posts(:thinking).tags << tags(:general).clone }
418 418
     assert_raise(ActiveRecord::HasManyThroughCantAssociateNewRecords) { posts(:thinking).clone.tags << tags(:general) }
419 419
     assert_raise(ActiveRecord::HasManyThroughCantAssociateNewRecords) { posts(:thinking).tags.build }
  420
+    assert_raise(ActiveRecord::HasManyThroughCantAssociateNewRecords) { posts(:thinking).tags.new }
420 421
   end
421 422
 
422 423
   def test_create_associate_when_adding_to_has_many_through

0 notes on commit 6712289

Please sign in to comment.
Something went wrong with that request. Please try again.