Jepzen
Jepzen

Reputation: 3192

How to do an order two times?

I have this piece of code

<% @hours.joins(:worker).order('workers.name').each do |hour| %>

<tr>
  <td><%= hour.worker.name %></td>
  <td><%= hour.job.date</td>
...

How can do an order on the hour.job.date after being sorted on worker.name?

Upvotes: 0

Views: 48

Answers (1)

Andrey Deineko
Andrey Deineko

Reputation: 52377

Just specify the columns you want to order by (in your case you'll want to join jobs table as well):

@hours.joins(:worker, :job).order('workers.name, jobs.date')

Upvotes: 1

Related Questions