Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #7503 (new defect)

Opened 2 years ago

Last modified 1 year ago

[PATCH] cascaded eager loading produces duplicate table aliases

Reported by: avrndef Assigned to: core
Priority: normal Milestone: 2.x
Component: ActiveRecord Version: edge
Severity: normal Keywords:
Cc:

Description

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.

Attachments

rails_patch (3.5 kB) - added by avrndef on 02/07/07 15:07:32.
The patch (test and fix both included)

Change History

02/07/07 15:07:32 changed by avrndef

  • attachment rails_patch added.

The patch (test and fix both included)

03/17/07 02:03:02 changed by josh

  • keywords set to unverified.

07/19/07 23:31:32 changed by lifofifo

  • keywords deleted.