Ruby on Rails Monday, January 19, 2015

Try this:

Sola::Dayly.group(:month).maximum(:peak_kw)


Explanation:
"find_by_sql" is to be used to get real records, not database calculations. The "Group", "Max" and other statements produce calculations, not real records.

If you want to do a raw SQL, do with "ActiveRecord::Base.connection.execute"

results = ActiveRecord::Base.connection.execute("select max(peak_kw) peak,month from sola_daylies group by month")

pp results
[0]

--
Daniel Loureiro

--
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/6966a806-ae58-4dac-93bb-77c725d129a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment