Its not so much that's it's shorter. They produce very different queries.
Rails by default selects all the columns explicitly instead of using *.

If eager_load is used this becomes even more of a hassle since you also
have to worry about selecting the the rows on the other table.

I really feel that there should be a built in method that matches the
behavior of .where which does not clobber.


On Thu, Nov 14, 2019, 22:49 Daniel <dan...@heath.cc> wrote:

> I like it, but I don't think it meets the criteria for inclusion in rails
> because it:
>
>  * Could easily be a gem.
>
>  * Is not meaningfully shorter.
>
>  * Requires the next person to read this code to know what this method
> does.
>
>
> On 11/15/19 3:03 AM, Andrew Kaspick wrote:
>
> +1
>
> On Thu, Nov 14, 2019 at 10:50 AM Max Calabrese <max.f.calabr...@gmail.com>
> wrote:
>
>> One little pet peeve of mine is that there is no way (afaik) to just add
>> additional columns to the select clause of a query. Like for example if I'm
>> joining and want a count or aggregate off the join table:
>>
>> User.joins(:answers)
>>        .select('users.*','AVG(answers.score) AS average_score')
>>
>>
>> What I would really want to do is just add this to the existing select
>> values of the scope:
>>
>> User.joins(:answers)
>>        .select_also('AVG(answers.score) AS average_score')
>>
>> *Is this a worthwhile feature? *
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Ruby on Rails: Core" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to rubyonrails-core+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/rubyonrails-core/a6c37abb-1b91-4eea-978e-5a483c2e30a7%40googlegroups.com
>> <https://groups.google.com/d/msgid/rubyonrails-core/a6c37abb-1b91-4eea-978e-5a483c2e30a7%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubyonrails-core+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-core/CAEUKiYH_JqVO4gAwdCXERqRPxsB2%2Bq5mkL4BJE4kfyWvvTNT_w%40mail.gmail.com
> <https://groups.google.com/d/msgid/rubyonrails-core/CAEUKiYH_JqVO4gAwdCXERqRPxsB2%2Bq5mkL4BJE4kfyWvvTNT_w%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubyonrails-core+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-core/91dffc18-a1b6-9865-776e-2ec8d45d84b7%40heath.cc
> <https://groups.google.com/d/msgid/rubyonrails-core/91dffc18-a1b6-9865-776e-2ec8d45d84b7%40heath.cc?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-core/CAH_9B3_UajjYomhL98k6YFUTDiUaqPnBfLpVWYaU9ZCB%3DqoztQ%40mail.gmail.com.

Reply via email to