title: Rails beginner - Best practice for querying multiple tables to retrieve lots of info at once
body: <p>I'm a Rails beginner and to learn it I'm building a simple time tracking app. I want to populate an administrator's dashboard with a ton of information from many tables with nested information.</p>
  
  <p>What would be the best practice for querying the database to request all of the data for one company to view a dashboard of all clients, projects, tasks, adjustments and minutes?</p>
  
  <p>Here's how the data is structured:</p>
  
  <p>Company
  has_many clients</p>
  
  <p>Client
  belongs_to company
  has_many projects</p>
  
  <p>Project
  belongs_to client
  has_many tasks</p>
  
  <p>Task
  belongs_to project
  has_many minutes</p>
  
  <p>Minute
  belongs_to task</p>
  
  <hr>
  
  <p>This data structure might be really bad. I don't know.</p>
  
  <p>An example view of the data:</p>
  
  <p>Activision<br>
   -- Website Redesign<br>
        --- Development<br>
           ---- 100 Minutes  </p>
  
  <p>I'm starting with this but I'm pretty but it could be totally backwards (Users belong to Companies):</p>
  
  <pre><code>    @clients = Client.find_all_by_company_id(current_user.company_id)
      @clients.each do |client| 
  
          project = Project.find_all_by_client_id(client.id)
          puts project.name
  
          project.each do |project|
  
              task = Task.find_all_by_project_id(project.id)
              puts task.name
  
          end
      end
  </code></pre>
  
  <p>I guess the question can also be asked: Is there a good book or resource that fully describes Rails ActiveRecord best practices?</p>