Colin Law wrote:
> If I have understood the problem correctly I think the first thing I
> would
> do is provide a method in model Task called duration that returns the
> total
> duration for that task by summing task.entries.time. Then all you need
> to
> pass to the report view is @tasks containing the tasks you are
> interested in
> and for each one task.duration is available to be displayed as desired.
Rails also provides aggregate functions so rather than writing a
duration method you could also write:
task = Task.find(:first)
task.entries.sum(:time)
Line 2 generates the following SQL:
SELECT sum("entries".time) AS sum_time FROM "entries" WHERE
("entries".task_id = 1)
--
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 post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---