我想對前10條記錄執行查詢。Rails更改查詢執行順序
所以,從Rails的控制檯I型:
Log.all.limit(10).where({"username"=>"peeyush"}).explain
這給:
Log Load (0.8ms) SELECT "logs".* FROM "logs" WHERE "logs"."username" = 'peeyush' LIMIT 10
顯然,LIMIT 10後發生的。
我嘗試運行:
Log.all.first(10).where({"username"=>"peeyush"}).explain
但是,這給出了一個錯誤:
NoMethodError: undefined method `where' for #<Array:0x0000000539acd8>
應如何查詢被執行?
後'where'條件,你應該給'第一(10)' – Pavan
,不能正常工作了!它提供了前10個日誌的數組,其中用戶名是peeyush。 – Peeyush
正如查詢站,這是輸出結果的權利。 – Pavan