Question: ```
Order belongs_to :delivery_timeslot
DeliveryTimeslot has_many :orders
DeliveryTimeslot belongs_to :timeslot
Timeslot has_many :delivery_timeslots 

```

I want to sort by id of timeslots:

```
Order.includes(delivery_timeslot: :timeslot).order('orders.delivery_timeslot.timeslot.id')

```

Please help. Thanks

Answer: 
You were very close:

```
Order.includes(delivery_timeslot: :timeslot).order('timeslots.id')

```
It makes no sense in SQL something like that. You have to specify just the table (optional, if it's not an ambiguous column) and the column. Try

```
Order.includes(delivery_timeslot: :timeslot).order('timeslots.id')

```