On 1 June 2014 15:51, Rodrigo Lueneberg <lists@ruby-forum.com> wrote:
> I see that, but sometimes you want to reuse code in the same relation.
> For instance if you do a query first using restricted columns and later
> you need to do a count based on the result. Let's say in the first
> relation with selected columns (col1, col2, etc.) you want to use to
> fill an array. From what I understand it doesn't work if I try to obtain
> a count from this relation. In fact, it doesn't make sense to do a
> relation just to do a count.
>
> In this scenario you would need two relations, one for the selected
> columns and another only for count. I would prefer do it using raw SQL,
> don't you agree?
Why not just do the count on the array? That would save running two
queries, one for the data and one for the count. Or am I missing
something?
Colin
>
> Rod
>
> josh.jordan@gmail.com wrote in post #1148444:
>> If you're calling count, it doesn't matter what select values you've
>> passed, since you're asking ActiveRecord to return an aggregate, not any
>> column values.
>>
>>
>> On Sun, Jun 1, 2014 at 9:19 AM, Rodrigo Lueneberg <lists@ruby-forum.com>
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/f824781ea8e576e1eec1c6341083e02d%40ruby-forum.com.
> 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: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLvEzDj0qd%2BkG1nKtSQaXZ97QcH1kLzkE%3DZ6PB7R7ubN6w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment