This project is archived and is in readonly mode.
Named scopes should implement #many? so they'll use COUNT(*)
-
Pratik
- Assigned user set to Pratik
- State changed from new to incomplete
Looks good. Why only named scope though ? It should be implemented for AssocitionCollections too.
-
Chris Kampmeier
- Tag changed from enumerable, named_scope, patch to associations, enumerable, named_scope, patch
OK, here's an updated patch that implements
#many?for AssociationCollections, too. -
Pratik
- State changed from incomplete to open
-
Tarmo Tänav
Wouldn't it be better to only fetch the primary keys for two records instead of counting them all just to find out if there is more than one?
-
Chris Kampmeier
Are you suggesting something like
SELECT [primary_key] FROM [table] ... LIMIT 2?I'm not sure whether that would be better or worse -- it seems like a speed difference would be dependent on how the database's
COUNTworks. It would definitely make the implementation more complicated, though: you'd have to branch in the code for when the collection is already loaded, etc.This patch just adds an analog of
#empty?and#any?for#many?, which probably shouldn't have been delegated toEnumerablein the first place.If using
LIMIT 2and such is an improvement, that would be great -- but for that kind of refactoring, I'd say a separate patch that affects all three would be more appropriate. -
Repository
- State changed from open to resolved
(from [4e8c36a7417e5d447c9b15d5c61df0c014ee6d3b]) Implement #many? for NamedScope and AssociationCollection using #size [#1500 Named scopes should implement #many? so they'll use COUNT(*) state:resolved]
Signed-off-by: Pratik Naik pratiknaik@gmail.com
http://github.com/rails/rails/commit/4e8c36a7417e5d447c9b15d5c61df0...
