#set_belongs_to_association_for doesn't ?

Hi all !

I've been meaning to ask for a while now. Please look at association_proxy:
http://dev.rubyonrails.org/browser/trunk/activerecord/lib/active_record/associations/association_proxy.rb#L105

Why are we only setting the primary key ? Why aren't we also copying
the reference to the owner object in the record ?

The following fails:

class Recipient < AR::B
  belongs_to :account
  validates_presence_of :account_id
  before_validation {|r| r.account = r.email.account if r.email }
end

class Email < AR::B
  has_many :recipients
  belongs_to :account
end

email = Email.new(...)
email.recipients.build(...)
email.save!

ActiveRecord::RecordInvalid: Validation failed: Recipients is invalid

The problem is actually caused by the fact that AR doesn't copy the
owner object in the newly instantiated has_many. Patching 1.2-stable
with the following:

Index: lib/active_record/associations/association_proxy.rb