title: Rails: Sort two different models (tables) together with multiple criterias
body: <p>I have two different models (Container and StockReceipt) that I need to merge and order for displaying in a table as deliveries. I'm currently sorting the records in the controller:<br></p>
  <blockquote>
  <p>stock_receipts = StockReceipt.where(:delivery_date.gt =&gt; 1.month.ago)</p>
  <p>containers = Container.joins(:shipment).where(:shipment =&gt; {:etd.gt =&gt; 1.month.ago})</p>
  <p>@deliveries = (stock_receipts + containers).sort!{|a,b| delivery_date(a) &lt;=&gt;
  delivery_date(b)}</p>
  </blockquote>
  <p>delivery_date being an helper method that returns the date according the class</p>
  <p>It works but I would like to sub-sort by supplier (in SQL: ORDER BY delivery_date, supplier_id). I could group_by(delivery_date).group_by(supplier) but it's a bit ugly.</p>
  <p>I'm wondering if there is a more elegant way to do this either in Rails or directly in SQL.</p>
  <p>Thanks guys,
  Gam</p>