Hello Folks. Please excuse my beginner’s ignorance …
My question regards database query performance vs. iterating over
nested results in an array. In the example below, a Project has many
Tasks. Tasks have a due date. When I display Projects, I would like to
also display the cumulative delay for all open Project Tasks based on
their due date, and today’s date.
Something like …
Project | Delay
XYZ | 5 days (4 tasks late, 1.25 day average delay)
… 100 records
As I learn RoR, I’ve discovered a couple ways I can do this. I can
perform the calculations in a single query. I can use the :include
option to build an array with nested children, and iterate over each
Project’s Tasks with something like parent.child.each.do. Or, finally,
I can issue 100 queries to the database, once for each record. Each
has advantages, but which is the most commonly accepted method in the
RoR community?
Thanks in advance
John