Rails: Order with nulls last

后端 未结 10 1467
悲哀的现实
悲哀的现实 2020-11-30 19:12

In my Rails app I\'ve run into an issue a couple times that I\'d like to know how other people solve:

I have certain records where a value is optional, so some recor

10条回答
  •  無奈伤痛
    2020-11-30 19:44

    In my case I needed sort lines by start and end date by ASC, but in few cases end_date was null and that lines should be in above, I used

    @invoice.invoice_lines.order('start_date ASC, end_date ASC NULLS FIRST')

提交回复
热议问题