rails model querying returns 11 records but no limit is set

wei*_*ney 5 activerecord ruby-on-rails limit

I am querying a set of data using a custom model Stat based on ActiveRecord, using sqlite3. It is obvious that the total amount of data is more than 100, but when I do my querying of all data, it always returns 11 records, no more of other data, and I did not set any limit to the statement, but in console it just add a limit of 11. limit Below is my code:

2.5.1 001 > Stat.all

  Stat Load (2.1ms)  SELECT  "stat".* FROM "stat" LIMIT ?  [["LIMIT", 11]]

2.5.1 002 > Stat.count

  (0.4ms)  SELECT COUNT(*) FROM "stat"
>> 105
Run Code Online (Sandbox Code Playgroud)

Is there any way to remove automatically added limit when I am doing this?

gao*_*fei 8

您的 Rails 版本是 5.1 还是更新版本?从 5.1 开始,Rails 只加载需要的记录。

要从数据库中查询所有记录,请Stat.all.to_a改用。

注意:这将返回Array而不是ActiveRecord_Relation

看到这个公关:https : //github.com/rails/rails/pull/28592