Ruby on Rails Thursday, February 4, 2016

On 4 February 2016 at 16:30, John Sanderbeck <lists@ruby-forum.com> wrote:
> I am trying to make this as efficient as possible which is why I was
> trying to do the group call.

Why?

>
> I was doing it in the Highchart definition which worked however it does
> many queries depending on how many initiatives there are.
>
> series: [{
> name: "Trainings",
> data: [
> <% Initiative.all.each do |initiative| %>
> ['<%= initiative.name %>',<%= Training.where("initiative_id = ?",
> initiative.id).count %>],
> <% end %>
> ]
> }],
>
> One of the issues is that there may not be any record count for a
> particular initiative so I also need to return a zero but still map the
> initiative.

initiative.trainings.count will return zero if there are no trainings.

Colin

--
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%3D0gLsFkYuxmzebSiZrkfipRHvouSdHqL%3DpKmiw8xuaUYo5vQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment