"Not unique table/alias" errors when upgrading to Rails 2.1

60 views
Skip to first unread message

Olly Lylo

unread,
Jun 3, 2008, 3:44:22 AM6/3/08
to Ruby on Rails: Talk
Hi

I've just attempted an upgrade from Rails 2.02 to 2.1 and I'm seeing
dozens of unit test failures with errors like this:

ActionView::TemplateError: Mysql::Error: Not unique table/alias:
'clients': SELECT count(DISTINCT `projects`.id) AS count_all FROM
`projects` LEFT OUTER JOIN `clients` ON `clients`.id =
`projects`.client_id INNER JOIN clients ON projects.client_id =
clients.id WHERE ((`clients`.company_id = 1) AND
((projects.status = 'Active')))

This is invalid SQL which Rails has generated -- it seems to be the
'INNER JOIN clients ON projects.client_id = clients.id' which is
causing the problem, but I can't figure out why this is happening.

Has anyone else experienced a similar problem with Rails 2.1, or can
anyone suggest what new features of 2.1 might be responsible for
introducing these errors?


Many thanks
Olly

Frederick Cheung

unread,
Jun 3, 2008, 4:12:52 AM6/3/08
to Ruby on Rails: Talk


On Jun 3, 8:44 am, Olly Lylo <ohea...@gmail.com> wrote:
> Hi
>
> I've just attempted an upgrade from Rails 2.02 to 2.1 and I'm seeing
> dozens of unit test failures with errors like this:
>

What's the code that produces that error?

Fred

Olly Lylo

unread,
Jun 3, 2008, 4:33:14 AM6/3/08
to Ruby on Rails: Talk
On Jun 3, 9:12 am, Frederick Cheung <frederick.che...@gmail.com>
wrote:
> What's the code that produces that error?

I believe it's this declaration:

has_many :active_projects,
:through => :clients,
:source => :projects,
:conditions => "projects.status = 'Active'",
:order => "ends_on DESC",
:include => :client

Reply all
Reply to author
Forward
0 new messages