You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
From an ActiveRecord perspective I am holding a Relation, that results in 10 records being returned. I don't understand, how the count for this relation could be higher.
Or to write it as rspec expectation:
If (for some reason) this problem is not as easily solvable:
Is there a work around? The best solution I could find is calling to_a, which of course will perform the full SQL query.
The text was updated successfully, but these errors were encountered:
When you use Model.count, ActiveRecord performs a SELECT COUNT, ignoring any limit parameter.
In this case, you can use: relation = Model.page(1).per_page(10) expect(relation.length).to eql(10)
or relation = Model.page(1).per_page(10) expect(relation.size).to eql(10)
.length will avoid another db query, but you must previously load the collection. .size seems to be the best option because if the collection has already been loaded, it will return its length just like calling .length. If it hasn't been loaded yet, it's like calling .count.
Reproduction
Expected
Actual
Explanation
From an ActiveRecord perspective I am holding a
Relation
, that results in 10 records being returned. I don't understand, how the count for this relation could be higher.Or to write it as rspec expectation:
Workaround?
If (for some reason) this problem is not as easily solvable:
Is there a work around? The best solution I could find is calling
to_a
, which of course will perform the full SQL query.The text was updated successfully, but these errors were encountered: