[LRUG] Named Scope Problem

Omar Qureshi omaraliqureshi at googlemail.com
Fri Oct 16 16:34:41 PDT 2009


b(either) - for clarity (as in that IS the SQL that will be output) more
than anything as well as producing correct code.

On Fri, Oct 16, 2009 at 6:21 PM, Andrew Stewart
<boss at airbladesoftware.com>wrote:

>
> 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
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20091017/73580fa9/attachment.html>


More information about the Chat mailing list