When using select method on ActiveRecord it replaces the default SELECT
clause. Sometimes you want to only add custom values (such as subquery from
related tables), and restoring the original clause (table.*) is painful. As
a squeel user, I don't really like using custom SQL and I don't want to
have to specify the table name (which can also be aliased, or in a
different database type).
There needs to be an option to either not replace the SELECT clause or to
restore it, for example with this scope on ActiveRecord::Base:
# after a long time I just found out you can do that, doesn't feel right in app
though
scope :select_all, -> { select(arel_table[Arel.star])) }
Steps to reproduce
class User < ActiveRecord::Baseend
users = User.select("5 AS custom")
Expected behavior
Original SELECT clause is kept (or ability to restore).
User.select("5 AS custom").to_sql# => SELECT `users`.*, 5 AS custom FROM `users`
Actual behavior
Original SELECT clause is replaced with a new one.
User.select("5 AS custom").to_sql# => SELECT 5 AS custom FROM `users`
System configuration
*Rails version*: 4.2.5.1
*Ruby version*: 2.2.3
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.