diff options
author | Michael Koziarski <michael@koziarski.com> | 2007-07-11 23:54:43 +0000 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2007-07-11 23:54:43 +0000 |
commit | 816522ecd8615bf96e8b932ac358fe9346b286ee (patch) | |
tree | ce3aeee6243bfb04b9e3ad1743734b33cbf74bdd /activerecord | |
parent | d4d4a08f6b064e47145b1abaca803654957f7a03 (diff) | |
download | rails-816522ecd8615bf96e8b932ac358fe9346b286ee.tar.gz rails-816522ecd8615bf96e8b932ac358fe9346b286ee.tar.bz2 rails-816522ecd8615bf96e8b932ac358fe9346b286ee.zip |
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
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/associations/has_many_through_association.rb | 3 | ||||
-rw-r--r-- | activerecord/test/associations/join_model_test.rb | 2 |
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 }, |