Rails: Sort nils to the end of a scope?

前端 未结 5 1496
半阙折子戏
半阙折子戏 2020-12-31 11:01

So, I have the following scope in my Photo model:

scope :best, order(:average_rating.desc)

The only problem is, the ratings were added to t

5条回答
  •  不思量自难忘°
    2020-12-31 11:17

    Well, I never found an approach that would work across DB drivers, so I just forced the value of all the records that were previously nil to be zero. That solved it for me, although it was a bit brutish. When the timer runs out I'll accept this since it is the solution I used, but if anyone revisits this and wants to provide an alternative answer in the future I'll be happy to accept a different answer later on.

提交回复
热议问题