Created
April 9, 2010 01:55
-
-
Save bronson/360792 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Named scopes are great. You can compose huge queries by gluing | |
parts together. | |
u = User | |
u = u.employee if params[:employee] | |
u = u.unvested if params[:unvested] | |
... etc. | |
u.length -- returns the number of users matching the query. | |
Works great if you specify either parameter. You end up with one of: | |
User.employee.length | |
User.unvested.length | |
User.unvested.employee.length | |
However, if both scope1 and scope2 are false, you end up with: | |
User.length | |
Which fails. | |
Is this a design hole in named scopes? Is there a way to | |
make this work? It should of course return a count of every | |
user if none of the scopes are applied. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment