Make create! on a has_many :through association return the association object. Not the collection. Closes #8786 [lifofifo]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7182 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Michael Koziarski
2007-07-11 23:54:43 +00:00
parent d4d4a08f6b
commit 816522ecd8
3 changed files with 5 additions and 2 deletions

View File

@@ -1,5 +1,7 @@
*SVN*
* Make create! on a has_many :through association return the association object. Not the collection. Closes #8786 [lifofifo]
* Move from select * to select tablename.* to avoid clobbering IDs. Closes #8889 [dasil003]
* Don't call unsupported methods on associated objects when using :include, :method with to_xml #7307, [manfred, jwilger]

View File

@@ -91,7 +91,8 @@ module ActiveRecord
def create!(attrs = nil)
@reflection.klass.transaction do
self << @reflection.klass.send(:with_scope, :create => attrs) { @reflection.klass.create! }
self << (object = @reflection.klass.send(:with_scope, :create => attrs) { @reflection.klass.create! })
object
end
end

View File

@@ -422,7 +422,7 @@ class AssociationsJoinModelTest < Test::Unit::TestCase
assert_equal(count + 1, post_thinking.tags.size)
assert_equal(count + 1, post_thinking.tags(true).size)
assert_nothing_raised { post_thinking.tags.create!(:name => 'foo') }
assert_kind_of Tag, post_thinking.tags.create!(:name => 'foo')
assert_nil( wrong = post_thinking.tags.detect { |t| t.class != Tag },
message = "Expected a Tag in tags collection, got #{wrong.class}.")
assert_nil( wrong = post_thinking.taggings.detect { |t| t.class != Tagging },