We should keep #to_sql and Arel as private API. The use-case to get the raw response from the driver remains. It would be nice to use ActiveRecord to build the SQL but get access to the raw driver result and not the mapped objects.
Do the lower level methods like `select_all`, `select_values`, etc. accept Relations? The current documentation is a bit confusing about the API (see http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/DatabaseStatements.html#method-i-select_values): * The method is in the docs, so it's assumed to be public. * We name the argument arel, which let's you in belief that arel is public as well * The example uses raw SQL. It would be good to get some light into the dark. On 10.04.2014, at 18:57, Rafael Mendonça França <[email protected]> wrote: > to_a is already used to return an Array of objects. > > select_rows seems good to me. > > But Arel and #to_sql seem to be used widely. > > Yes, this is sad. They was never public API. But I think we can't do anything > besides make clear what is public and what is private API. > > > Rafael Mendonça França > http://twitter.com/rafaelfranca > https://github.com/rafaelfranca > > > On Thu, Apr 10, 2014 at 1:53 PM, Dheeraj Kumar <[email protected]> > wrote: > How about #to_a and #to_h instead? > > #to_h would return the results as a hash, useful when you are retrieving a > single row, but many columns. > #to_a would return the results as an array of hashes, useful when you have > multiple rows. > > > On Thu, Apr 10, 2014 at 10:11 PM, Rafael Mendonça França > <[email protected]> wrote: > +1, too. > > I was planning to add this method because calling `to_sql` is not a good > solution. I think the name we choose was `select_all`. > > Rafael Mendonça França > http://twitter.com/rafaelfranca > https://github.com/rafaelfranca > > > On Thu, Apr 10, 2014 at 1:03 PM, Dheeraj Kumar <[email protected]> > wrote: > +1, I do this a lot. > > On Apr 10, 2014 9:30 PM, "Evgeniy Sokovikov" <[email protected]> wrote: > Hello. Is it possible to get raw sql query result from ActiveRecord::Relation > ? > > > > > > > > Now I can make it this way: > > sql = Note.select('count(*), commit_id').group(:commit_id).to_sql > > > > > > > ActiveRecord::Base.connection.execute(sql).to_a > > > > > > > > > > > > > > I would like something like this: > > > > Note.select('count(*), commit_id').group(:commit_id).raw > > > > > > > > > > > > > > But didn't find such method. > > > -- > 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 http://groups.google.com/group/rubyonrails-core. > For more options, visit https://groups.google.com/d/optout. > > -- > 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 http://groups.google.com/group/rubyonrails-core. > For more options, visit https://groups.google.com/d/optout. > > > -- > 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 http://groups.google.com/group/rubyonrails-core. > For more options, visit https://groups.google.com/d/optout. > > > -- > 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 http://groups.google.com/group/rubyonrails-core. > For more options, visit https://groups.google.com/d/optout. > > > -- > 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 http://groups.google.com/group/rubyonrails-core. > For more options, visit https://groups.google.com/d/optout. -- 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 http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/d/optout.
