Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 7182

Show
Ignore:
Timestamp:
07/11/07 23:54:43 (1 year ago)
Author:
nzkoz
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/CHANGELOG

    r7167 r7182  
    11*SVN* 
     2 
     3* Make create! on a has_many :through association return the association object.  Not the collection.  Closes #8786 [lifofifo] 
    24 
    35* Move from select * to select tablename.* to avoid clobbering IDs. Closes #8889 [dasil003] 
  • trunk/activerecord/lib/active_record/associations/has_many_through_association.rb

    r6909 r7182  
    9292      def create!(attrs = nil) 
    9393        @reflection.klass.transaction do 
    94           self << @reflection.klass.send(:with_scope, :create => attrs) { @reflection.klass.create! } 
     94          self << (object = @reflection.klass.send(:with_scope, :create => attrs) { @reflection.klass.create! }) 
     95          object 
    9596        end 
    9697      end 
  • trunk/activerecord/test/associations/join_model_test.rb

    r7119 r7182  
    423423    assert_equal(count + 1, post_thinking.tags(true).size) 
    424424 
    425     assert_nothing_raised { post_thinking.tags.create!(:name => 'foo') } 
     425    assert_kind_of Tag, post_thinking.tags.create!(:name => 'foo') 
    426426    assert_nil( wrong = post_thinking.tags.detect { |t| t.class != Tag }, 
    427427                message = "Expected a Tag in tags collection, got #{wrong.class}.")