title: "Complex" grouping and indexing in rails?
body: <p>I have a problem to which I can't seem to find a simple solution.</p>
  
  <p>I want to achieve the following:<br>
  * i have a list of tasks, each with an owner and a due date<br>
  * i want to display a list of all tasks grouped by owner<br>
  * i want to sort the owners based on the due dates: e.g. The owner with the lowest due date first, followed by the owner with the second lowest, etc<br>
  * I want to be able to paginate the results, preferable with will_paginate</p>
  
  <p>To ilustrate, this would be a result i am looking for:</p>
  
  <p>Harry<br>
  - task 1, due date 1<br>
  - task 3, due date 4<br>
  Ben<br>
  - task 2, due date 2<br>
  Carol<br>
  - task 4, due date 3  </p>
  
  <p>So far, I can query for all owners with tasks, sort them on a virtual attribute with their "earliest due date" and then display them <em>and</em> their tasks in a view.</p>
  
  <p>There are multiple problems with this approach, imo:<br>
  * i run multiple queries from the view (owner.tasks.each etc). I always learned that running queries from the view is bad<br>
  * i'm doing the sorting by loading all records in memory (virtual attribute), which could get problematic with large records set.
  * I have no idea how i can get pagination in on this, that will be sensitive to the amount of tasks displayed</p>
  
  <p>I can't seem to crack this nut, so any help or hints would be greatly appreciated!<br>
  Erwin</p>