title: Complex query in Rails
body: <p>I'm trying to build a simple solver web application for the <a href="https://en.wikipedia.org/wiki/Vehicle_routing_problem" rel="nofollow noreferrer">VRP</a>. My question is on how can i build a query that returns every customer with his user's username, longitude, latitude and his products with all product columns <strong>and</strong> the quantity of product's last stock?</p>
  
  <p>The diagram of the database:
  <a href="https://i.stack.imgur.com/rkxIm.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rkxIm.jpg" alt="database scheme"></a>
  Customer and User relationship is one-to-one (User is a superclass of Customer)</p>
  
  <p>Salesman and User relationship is one-to-one (User is a superclass of Salesman)</p>
  
  <p>Salesman and Customer relationship is one-to-many (a Salesman has many Customers)</p>
  
  <p>Customer and Product relationship is one-to-many (a Customer has many Products)</p>
  
  <p>Product and Stock relationship is one-to-many (there is a need of recording every stock change)</p>
  
  <p><em>Any suggestion of changing the database scheme is welcome</em> </p>