aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-10-15 08:09:04 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-10-15 08:09:04 +0000
commit671228942d1a49f223739f249728eebbc590f66e (patch)
tree93ed66d1b53ea1267cd3e81ecb8389e921f00f83 /activerecord
parent333463679ad4c66e43d1cbd11bec3570e9c719e0 (diff)
downloadrails-671228942d1a49f223739f249728eebbc590f66e.tar.gz
rails-671228942d1a49f223739f249728eebbc590f66e.tar.bz2
rails-671228942d1a49f223739f249728eebbc590f66e.zip
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
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG2
-rw-r--r--activerecord/lib/active_record/associations/has_many_through_association.rb1
-rw-r--r--activerecord/test/associations/join_model_test.rb1
3 files changed, 4 insertions, 0 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index 92852375ec..1e2907c50b 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Alias association #build to #new so it behaves predictably. #8787 [lifofifo]
+
* Add notes to documentation regarding attr_readonly behavior with counter caches and polymorphic associations. Closes #9835 [saimonmoore, rick]
* Observers can observe model names as symbols properly now. Closes #9869 [queso]
diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb
index 62839c4637..5bb306c060 100644
--- a/activerecord/lib/active_record/associations/has_many_through_association.rb
+++ b/activerecord/lib/active_record/associations/has_many_through_association.rb
@@ -88,6 +88,7 @@ module ActiveRecord
def build(attrs = nil)
raise ActiveRecord::HasManyThroughCantAssociateNewRecords.new(@owner, @reflection.through_reflection)
end
+ alias_method :new, :build
def create!(attrs = nil)
@reflection.klass.transaction do
diff --git a/activerecord/test/associations/join_model_test.rb b/activerecord/test/associations/join_model_test.rb
index a10c1b156c..6b67b15664 100644
--- a/activerecord/test/associations/join_model_test.rb
+++ b/activerecord/test/associations/join_model_test.rb
@@ -417,6 +417,7 @@ class AssociationsJoinModelTest < Test::Unit::TestCase
assert_raise(ActiveRecord::HasManyThroughCantAssociateNewRecords) { posts(:thinking).tags << tags(:general).clone }
assert_raise(ActiveRecord::HasManyThroughCantAssociateNewRecords) { posts(:thinking).clone.tags << tags(:general) }
assert_raise(ActiveRecord::HasManyThroughCantAssociateNewRecords) { posts(:thinking).tags.build }
+ assert_raise(ActiveRecord::HasManyThroughCantAssociateNewRecords) { posts(:thinking).tags.new }
end
def test_create_associate_when_adding_to_has_many_through