aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG2
-rw-r--r--activerecord/lib/active_record/associations/has_many_through_association.rb3
-rw-r--r--activerecord/test/associations/join_model_test.rb2
3 files changed, 5 insertions, 2 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index 9ea6ff93bc..cc0f1c924d 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -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]
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 7a55334912..b75de4d23f 100644
--- a/activerecord/lib/active_record/associations/has_many_through_association.rb
+++ b/activerecord/lib/active_record/associations/has_many_through_association.rb
@@ -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
diff --git a/activerecord/test/associations/join_model_test.rb b/activerecord/test/associations/join_model_test.rb
index 2e1b4dae88..a784a8eefd 100644
--- a/activerecord/test/associations/join_model_test.rb
+++ b/activerecord/test/associations/join_model_test.rb
@@ -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 },