association assignment with delayed database access


I've been digging into the discussion around nested mass assignment,
and am trying my hand at a plugin that adds what I consider the
optimal model behavior. But I'm running into a solid problem trying to
use association proxies without modifying anything in the database.

My take is that there should be three very discrete phases to
updating: assignment, validation, and saving. Right now this is
somewhat mixed, because _certain_ assignments will touch the database.
Could this change? Besides being a general improvement (I think), it
would be very helpful for nested mass assignment.

For example:

  @user = User.find(params[:id])
  @user.attributes = params[:user][:user][:address])
    redirect_to @user
    render :action => 'edit'.

Right now the `' would disassociate (or destroy) an
existing address, even if the @user was ultimately invalid and the new
address was not saved. What I would like to see is for assigning (or
building) a new address to make in-memory changes that are queued up
for the final #save transaction. The association proxies, instead of
updating the database, could shuffle records into arrays where the
save method picked up on them and took the final action ... in a
single transaction.

That is, I would like to see the #save method ultimately work
something like this:

  def save
    self.class.transaction do
      create_or_update &&
        create_new_associated_records &&
        disassociate_marked_associated_records &&

I'm sure it would be a bit trickier than that (especially with new
records and ids), but what do y'all think of the direction? This is
something I would work on, perhaps with a bit of assistance.