I have simple Booking and Client models:
class Client
include DataMapper::Resource
property :id, Serial
property :name, String, required: true
property :email, String, required: true
#....
has n, :bookings, constraint: :destroy
end
class Booking
include DataMapper::Resource
property :id, Serial
property :start_date, Date
property :end_date, Date
#....
belongs_to :client
end
In the view a table is generated as expected:
<% @bookings.each do |booking| %>
<tr>
<td><%= booking.client.name %></td>
<td><%= booking.start_date %></td>
<td><%= booking.end_date %></td>
....
</tr>
<% end %>
And I want order the table as by clicking on the respective table column heading.
I can get the table to sort by :start_date, or :end_date, and also by :client_id, but :client_id isn't very useful; I want to be able to sort by the :name attribute of the Client model with :client_id
Could someone tell me what format my controller needs to take, please?
get '/bookings' do
@bookings = Booking.all(order: :client_id.name) #no method error
@bookings = Booking.all(order: [:client_id][:name]) #can't convert to integer
erb :bookings
end
Thanks