searchlogic icon indicating copy to clipboard operation
searchlogic copied to clipboard

Double JOIN with order

Open ZenCocoon opened this issue 16 years ago • 5 comments

I guess the example below will speak on it's own :

named_scope :select_with_authors, :joins => "LEFT OUTER JOIN authors ON authors.id = posts.author_id"

Post.select_with_authors.descend_by_author_name ActiveRecord::StatementInvalid: Mysql::Error: Not unique table/alias: 'authors': SELECT posts.* FROM posts INNER JOIN authors ON authors.id = posts.author_id LEFT OUTER JOIN authors ON authors.id = posts.author_id ORDER BY authors.name DESC

Please let me know if you like further details.

ZenCocoon avatar Sep 15 '09 11:09 ZenCocoon

this happens with :include in the named_scope, too.

pschrammel avatar May 04 '10 09:05 pschrammel

Can somebody confirm that if you use mislav's will_paginate in version 2.3.11 this error disappears. Using 2.3.2 fails (at least for me).

experteer avatar Jun 24 '10 06:06 experteer

I keep running into this problem when I try to eager load one of my associations with :include. It does a LEFT OUTER JOIN for the search conditions and an INNER JOIN to include data for the eager load.

demersus avatar Oct 19 '10 17:10 demersus

Bump

laurynas avatar Nov 26 '10 08:11 laurynas

Just ran into this today with the INNER JOIN for :include'd has_one association and LEFT OUTER JOIN for search conditions on the same has_one association. MySQL throws a "Not unique table/alias" error.

graywh avatar Mar 02 '12 16:03 graywh