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

前端 未结 4 1977
南方客
南方客 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:39

    All you need to do is sum the queries:

    result1 = Model.where(condition)
    result2 = Model.where(another_condition)
    
    # your final result
    result = result1 + result2
    

提交回复
热议问题