Skip to content
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

Open
wants to merge 17 commits into
base: ald/master
Choose a base branch
from
Open

final wave of task list by Audrey #104

wants to merge 17 commits into from

Conversation

Dreedle
Copy link

@Dreedle Dreedle commented Nov 17, 2015

It isn't all that beautiful, but it works.

def count_incomplete
t = self.tasks
incomplete = t.where(completed_date: nil)
incomplete.length
Copy link

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.

@Dreedle
Copy link
Author

Dreedle commented Dec 4, 2015

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants