Re: [Rails] getting find_by_sql to return the numeric value rather than an object that contains the value as an attribute
On 6 March 2012 15:38, Michael Pavling <pavling@gmail.com> wrote:
> On 6 March 2012 15:28, Colin Law <clanlaw@googlemail.com> wrote:
>> Note the .sum on the end of find_by_sql
>
> Ah, yeah. Do it in the method.
Is there not a more railsy way of doing what the op wants rather than
using find_by_sql? At least it would be more efficient I think to do
the * 0.006... after the find.
find_by_sql(["SELECT SUM(distance) as sum FROM
reports WHERE unit_id=? AND id >= ? AND id <= ?", unit_id, report1,
report2]).sum * 0.000621371192
Colin
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home