I have a Rails command:
Product.includes(:sale, :product_description).select('distinct on (size) *')
It is my understanding that when I run this command, Rails will eagerly load the results into memory, and since there are only 4 sizes, the result should only contain 4 records. However, if I do something like:
result = Product.includes(:sale, :product_description).select('distinct on (size) *')
and then do: result.size
. The result will be a count of all the product records, which is 435. But if I do: result.length
then I will get the expected response, which is 4.
Why am I getting different results with length
and size
? I thought that by using includes
everything is eagerly loaded so length
and size
should return the same count?
Also note, if I run length
first and then size
, both return the correct result of 4. But if I run size
first, then I get the wrong response of 435.