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_sqlActiveRecord::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.
+1, I do this a lot.
--
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-co...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.
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.
#to_sql + #execute is widely used, because it's a legitimate, and popular use case. Sometimes, we just need pure ruby objects. AR models become an overhead in those situations.