Model.first 不会从表中检索第一条记录。相反,它从表中检索任何随机记录。
eg:
Merchant.first
Query
SELECT "merchants".* FROM "merchants" LIMIT 1
=> <Merchant id: 6, merchant_name: "Bestylish", description: "", description_html: "" >
Instead the query should be
SELECT "merchants".* FROM "merchants" ORDER BY "merchants"."id" ASC LIMIT 1;
Why it doesnot retrive the first record
最佳答案
Model.first 将使用数据库的默认排序。 例如。在 Postgresql 中默认排序不一定是一个 id。
关于ruby-on-rails - Model.first 不从表中检索第一条记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18828381/