title: Rails 3.1.2: Set association without saving
body: <p>I want to set an association on an activerecord object without having that association be persisted, so that what I've just set it to is returned when I invoke the association method. Is there a nice way of doing that?</p>
  
  <p>Example:</p>
  
  <pre><code>class Bar &lt; ActiveRecord::Base
     has_many :foos
  end
  
  class Foo &lt; ActiveRecord::Base
     belongs_to :bar
  end
  
  this_bar = Bar.find(1)
  this_foo = Foo.find(1)
  
  this_bar.foos = [this_foo] # This performs a save, which I don't want
  this_bar.foos #=&gt; should return [this_foo]
  # further computation #
  </code></pre>
  
  <p>(What I'm trying to achieve is allow the user to see a "preview" of what the object will look like after update, but still give the option to cancel out the update.)</p>