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
Is there any way to remove automatically added limit when I am doing this?
Is your Rails version 5.1 or newer? Since 5.1, Rails only loads needed records.
To query all records from database, use Stat.all.to_a
instead.
Note: this returns Array
instead of ActiveRecord_Relation
See this PR: https://github.com/rails/rails/pull/28592
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With