title: Rails transaction: save data in multiple models
body: <h2>my models</h2>
  
  <pre><code>class Auction
    belongs_to :item
    belongs_to :user, :foreign_key =&gt; :current_winner_id
    has_many :auction_bids
  
  end
  
  class User
    has_many :auction_bids
  
  end
  
  class AuctionBid
    belongs_to :auction
    belongs_to :user
  
  end
  </code></pre>
  
  <h2>current usage</h2>
  
  <p>An auction is displayed on the page, the user enters an amount and clicks bid. Controller code might look something like this:</p>
  
  <pre><code>class MyController
    def bid
      @ab = AuctionBid.new(params[:auction_bid])
      @ab.user = current_user
      if @ab.save
        render :json =&gt; {:response =&gt; 'YAY!'}
      else
        render :json =&gt; {:response =&gt; 'FAIL!'}
      end
    end 
  end
  </code></pre>
  
  <h2>desired functionality</h2>
  
  <p>This works great so far! However, I need to ensure a couple other things happen. </p>
  
  <ol>
  <li><code>@ab.auction.bid_count</code> needs to be incremented by one.</li>
  <li><code>@ab.user.bid_count</code> needs to be incremented by one</li>
  <li><code>@ab.auction.current_winner_id</code> needs to be set to <code>@ab.user_id</code></li>
  </ol>
  
  <p>That is, the <code>User</code> and the <code>Auction</code> associated with the <code>AuctionBid</code> need values updated as well in order for the <code>AuctionBid#save</code> to return true.</p>