[LRUG] Named Scope Problem

Andrew Stewart boss at airbladesoftware.com
Fri Oct 16 10:21:22 PDT 2009


On 14 Oct 2009, at 16:29, Matthew Rudy Jacobs wrote:
> If I were you I'd write the :joins as a string.
> I don't think the nested hash conditions syntax is very clear anyway,
> (especially with 5 levels of nesting)


I wrote the :joins as a string and it all worked as hoped (on Rails  
2.1.0 and 2.3.4).  Thanks for the suggestion.

As for clarity, here are the versions so others may judge ;)

(a)         :joins => {:d => {:c => {:b => {:a => :account}}}}

(b)(i)      :joins => "INNER JOIN `d` ON `d`.id = `e`.d_id INNER JOIN  
`c` ON `c`.id = `d`.c_id INNER JOIN `b` ON `b`.id = `c`.b_id INNER  
JOIN `a` ON `a`.id = `b`.a_id INNER JOIN `accounts` ON `accounts`.id =  
`a`.account_id"

(b)(ii)     :joins => "INNER JOIN `d` ON `d`.id = `e`.d_id " +
                      "INNER JOIN `c` ON `c`.id = `d`.c_id " +
                      "INNER JOIN `b` ON `b`.id = `c`.b_id " +
                      "INNER JOIN `a` ON `a`.id = `b`.a_id " +
                      "INNER JOIN `accounts` ON `accounts`.id =  
`a`.account_id"

Personally I prefer (a) but it has the unfortunate drawback of  
producing left outer rather than inner joins....

Cheers,
Andy Stewart

------
http://airbladesoftware.com



More information about the Chat mailing list