How do I combine results from two queries on the same model?

前端 未结 4 1995
南方客
南方客 2021-02-15 13:56

I need to return exactly ten records for use in a view. I have a highly restrictive query I\'d like to use, but I want a less restrictive query in place to fill in the results i

4条回答
  •  南旧
    南旧 (楼主)
    2021-02-15 14:36

    I think you can do all of this in one query:

     Article.published.order('listed ASC, created_at DESC').limit(10)
    

    I may have the sort order wrong on the listed column, but in essence this should work. You'll get any listed items first, sorted by created_at DESC, then non-listed items.

提交回复
热议问题