Hello Ken,

Even though I understand, and agree to an extent with your point, I
don't think developers should be mislead. Current behavior:

Model.all.count #=> should indeed execute a count on all records
Model.all.size #=> if the records are not loaded it should return the
collection size, otherwise fallback to count
Model.all.length #=> forces the load and counts the collection

What I'm suggesting is the following change:

Model.all.count #=> no changes
Model.<some limitation / scope>.count #=> compute the limitation
clauses (eg where) and execute a count statement based on those
limitators
Model.all.size #=> no changes
Model.<some limitation / scope>.size #=> if the records are not loaded
it should return the collection size, otherwise fallback to count
described above
Model.all.length #=> no changes
Model.<some limitation / scope>.length #=> no changes

What you guys think of this behavior?

Even though the changed behavior of count and size _will not_ be
backwards compatible if you are relying on it to do a full table count
statement, it will be more precise and less ambiguous. Doing a full
table count when you're using limitations is, in my honest opinion,
misleading and should be considered a bug.

I'm currently looking at ActiveRecord::Relation#arel to try and figure
out the best way to compute the current limitators (eg where) and
issue an arel count based on them. If anyone has any pointers it would
be of great assistance :)

Since any change of the current behavior would potentially be
backwards incompatible, it would be more helpful to test these changes
as a plugin/gem and see how it goes. Please let me know if you have
any pointers on the best way to get arel to perform this "scoped"
count.

Best regards,
DBA

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to rubyonrails-c...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-core+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.

Reply via email to