Has one relationship through join table - orphaned records on update

I have set up the following relationships Rails 2.3.5 and on update I
am finding that orphaned records are generated. Are my relationships
wrong or is there a recommended way to manage these orphaned records
on an update. Code is detailed below:

class User

has_many :management_assignments, :foreign_key => :manager_id
has_many :listings, :through => :management_assignments

class ManagementAssignment < ActiveRecord::Base

attr_accessible :manager_id, :id, :listing_id, :assignor_id, :status,
:assignment_date, :completed_date
belongs_to :manager, :class_name => ‘User’
belongs_to :assignor, :class_name => ‘User’
belongs_to :listing

class Listing
has_one :management_assignment, :dependent
=> :destroy
has_many :managers, :through => :management_assignments, :source
=> :user

accepts_nested_attributes_for :management_assignment, :allow_destroy
=> true

My update controller action is a bulk update which uses a nested form
to change the manager on the relationship as follows:

def update_multiple
@listings = Listing.find(params[:listing_ids])
@listings.each do |listing|
listing.last_updated_by = current_user
listing.update_attributes!(params[:listing].reject { |k,v|
v.blank? })
flash[:notice] = “Updated listings!”
redirect_to admin_listings_path

As a noob any help or feedback as to how to eliminate these orphaned
records would be much appreciated.



Interestingly when editing the records individually no orphaned
records are created. This would appear to have something to do with
the Params hash being returned to the server and the nested fields

The params hash being returned for a bulk update is detailed below:

Parameters: {“listing_ids”=>[“1”, “2”, “3”], “commit”=>“Submit”,
“action”=>“update_multiple”, “_method”=>“put”,
“listing”=>{“zhtranslator_id”=>"", “frtranslator_id”=>"",
“assignment_date”=>“2010-04-12”, “status”=>“editing”,
“manager_id”=>“2”, “assignor_id”=>“1”}, “jptranslator_id”=>"",
“kotranslator_id”=>"", “detranslator_id”=>"", “idtranslator_id”=>“3”,
“ownership_attributes”=>{“owner_id”=>""}}, “controller”=>“admin/

For an individual edit/update the management_assignment_attributes
hash contains the listing id (ie “id” => “4”) whereas there are no ids
in the management_assignment params hash for a bulk update, so my
sense is that I somehow have to get the listing ids inside this params
hash to avoid the orphaned record problem. Any ideas would be much