提交 67122894 编写于 作者: J Jeremy Kemper

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
上级 33346367
*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]
......
......@@ -88,6 +88,7 @@ def delete(*records)
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
......
......@@ -417,6 +417,7 @@ def test_raise_error_when_adding_new_record_to_has_many_through
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册