In master, there's a regression in the new association handling cod. Way back 
in a patch I submitted to 3.0 to fix similar problems with eager loading, there 
was another edge case that got "accidentally" fixed as well.

The issue is this:

In JoinAssociation#aliased_table_name_for, the following code is run to 
generate an aliased table name:

name = connection.table_alias_for 
"#{pluralize(reflection.name)}_#{parent_table_name}#{suffix}"
table_index = aliases[name] + 1
name = name[0, connection.table_alias_length-3] + "_#{table_index}" if 
table_index > 1

After this, aliases[name] is incremented. But since the value of "name" is now 
the new, aliased table name, the effect is that we end up with an aliases hash 
that looks something like this (taken from a multiply self-referential 
parent-child join:

{
  "people"=>1, "children_people"=>1,
  "children_people_2"=>2, "parents_people"=>1, 
  "parents_people_2"=>2
}

As you can see, instead of counting aliases against children_people, we began 
counting against the aliased table name itself. This leads the JoinDependency 
to create invalid JoinAssociations (2 against children_people_2 and 
parents_people_2 in this case, which means twice it incremented children_people 
and landed on the same table name), and creates table name collisions.

The patch at 
https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/6423 fixes 
the regression and adds a test to cover it in the future.

-- 
Ernie Miller
http://metautonomo.us
http://github.com/ernie
http://twitter.com/erniemiller

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.

Reply via email to