Certain eager loading statements generate non-unique table aliases.
The statement
One.find(:all, :include => [{:one_two => :two}, :two])
generates
Exception raised:
Class: <ActiveRecord::StatementInvalid>
Message: <"Mysql::Error: #42000Not unique table/alias: 'one_two': SELECT one.`id` AS t0_r0, one_two.`id` AS t1_r0, one_two.`one_id` AS t1_r1, one_two.`two_id` AS t1_r2, two.`id` AS t2_r0, twos_one.`id` AS t3_r0 FROM one LEFT OUTER JOIN one_two ON one_two.one_id = one.id LEFT OUTER JOIN two ON two.id = one_two.two_id LEFT OUTER JOIN one_two ON one_two.one_id = one.id LEFT OUTER JOIN two twos_one ON twos_one.id = one_two.two_id ">
I think (but I am not certain) that the problem occurs only when the table names are singular. I could not reproduce the problem with any existing fixture class, so I added my own.
The problem is caused by the hash JoinDependency#table_aliases being keyed with both strings and symbols. The solution was to use a HashWithIndifferentAccess for JoinDependency#table_aliases.