-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
final wave of task list by Audrey #104
base: ald/master
Are you sure you want to change the base?
Conversation
… and show for people
…g in person index
def count_incomplete | ||
t = self.tasks | ||
incomplete = t.where(completed_date: nil) | ||
incomplete.length |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally we should prefer to use count
on ActiveRecord relations (the array-link objects that are returned by all
and where
), because they "compose" together better and allow ActiveRecord to use more efficient SQL code.
If you try it out in rails console vs. using length
you should be able to see how the generated SQL code is different.
Thanks for the comments, Charles! I hadn't even been thinking about whether I was putting id's on elements that are repeated from a loop. |
It isn't all that beautiful, but it works.