associations and nested_attributes internals... looking for patch guidance


I ran into something that works in Rails 3.0.x, but no longer works in Rails 3.1.x and it seems to be valid usage and I was wondering if somebody more familiar with the activerecord internals could point me in the right direction...

Here's my basic use case using nested attributes:

project = Project.find 1 params[:task] = {:name => 'task', :project_attributes => {'1' => {:name => 'project'}}}

# this works in rails 3.0.11 (the project name is assigned correclty) # this does not work in rails 3.1.3 params[:task]

# this works in rails 3.1.3 # even though we're creating the new task from the relation owned by the project object, we need to pass the project id in explicitly so that it updates correctly params[:task].merge(:project_id =>

There has been a lot of refactoring of active record between Rails 3.0 and 3.1, so I'm a bit lost in the current code, but I've found the main culprit to be in nested_attributes.rb

The line with: record = send(association_name)

... that correctly returns the project record in Rails 3.0, but it's nil in 3.1.

I've traced (I think) the origination of this issue in Rails 3.1 to

When building the association (the "owner" value in this scope has the valid project) we lose reference to the project owner value which we would need to successfully assign the nested attributes.

I'll provide a patch for this issue, but I feel I'm missing something simple here on how to assign the owner of that association before it tries to assign the nested attributes. If somebody can point me in the right direction, I'll work on a patch.


3 weeks later (got busy), here's my patch...