There’s an easy way around this, though. Inside of where, you can use the positive scope you added to the Review class:
That way, the idea of what makes a review a positive review is still only in one place.
Scopes are great. In the right place, they can make querying your data easy and fun. But if you want to avoid N+1 queries, you have to be careful with them.
So, if a scope starts to cause you trouble, wrap it in an association and preload it. It’s not much more work, and it’ll save you a bunch of SQL calls.
Pushing through tutorials, and still not learning anything?
Have you slogged through the same guide three times and still don't know how to build a real app?
In this free 7-day Rails course, you'll learn specific steps to start your own Rails apps — without giving up, and without being overwhelmed.
You'll also discover the fastest way to learn new Rails features with your 32-page sample of Practicing Rails: Learn Rails Without Being Overwhelmed.
Sign up below to get started:
Thanks! You should get an email from me in a few minutes with your free sample chapter.
While you wait, I'd love to <a href="https://icosahedron.website/@justinweiss">meet you on Mastodon</a>. You can learn a little bit more about Ruby each day -- I share the best Ruby and Rails articles I read. And it's great for short conversations and answering questions about software development.