has_many :through, multi model form unable to save new child

James West wrote:

James West wrote: Sorry, I ommited to post the actual error which is now

Cannot modify association 'User#addresses' because the source reflection class 'Address' is associated to 'UserRole' via :has_many.

Further investigation shows that the address record seems to have the correct SQL being generated for it. I just updated Rails from 2.3.2 to 2.3.3 to see if that made a difference but this has had no effect.

Processing Admin::UsersController#update (for 127.0.0.1 at 2009-08-08 07:37:27) [PUT]   Parameters: {"user"=>{"name"=>"test2", "public_name"=>"Test 2", "addresses_attributes"=>{"1249713438151"=>{"city"=>"ccc", "postcode"=>"ccc", "house"=>"ccc", "town"=>"ccc", "street"=>"ccc"}}, "password_confirmation"=>"", "password"=>""}, "commit"=>"Update", "authenticity_token"=>"xO3gOpJcO08UGEzEtifnCIKqEOhwtDaz0UkM7X7aAQY=", "id"=>"1"}   e[4;36;1mUser Load (0.0ms)e[0m e[0;1mSELECT * FROM "users" WHERE ("users"."id" = 1) LIMIT 1e[0m   e[4;35;1mTheme Load (0.0ms)e[0m e[0mSELECT * FROM "themes" WHERE ("themes"."active" = 't') LIMIT 1e[0m

ActiveRecord::HasManyThroughCantAssociateThroughHasManyReflection (Cannot modify association 'User#addresses' because the source reflection class 'Address' is associated to 'UserRole' via :has_many.):   app/controllers/admin/users_controller.rb:72:in `update'   app/controllers/admin/users_controller.rb:71:in `update'   C:/Development/InstantRails/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'   C:/Development/InstantRails/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'   C:/Development/InstantRails/ruby/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'   C:/Development/InstantRails/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start'   C:/Development/InstantRails/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'   C:/Development/InstantRails/ruby/lib/ruby/1.8/webrick/server.rb:95:in `start'   C:/Development/InstantRails/ruby/lib/ruby/1.8/webrick/server.rb:92:in `each'   C:/Development/InstantRails/ruby/lib/ruby/1.8/webrick/server.rb:92:in `start'   C:/Development/InstantRails/ruby/lib/ruby/1.8/webrick/server.rb:23:in `start'   C:/Development/InstantRails/ruby/lib/ruby/1.8/webrick/server.rb:82:in `start'

Rendered rescues/_trace (484.0ms) Rendered rescues/_request_and_response (0.0ms) Rendering rescues/layout (internal_server_error)

OK this is a Rails bug. I have done extensive testing now and am able to prove that the code works on a has many but has_many :through fails. I'll report it as a bug if someone can tell me how?

Thanks

James