In this episode, we focus on improving how our app displays import records by adding some simple but powerful query scopes. First up, we’ll limit our imports so we only see the ones that haven’t been completed yet. We do this by creating a new notCompleted
scope right on our Import model, using the handy completed_at
database column we set up earlier. With this in place, finished imports are filtered out automatically.
Next, we want to scope imports by which model they belong to—say, customers or products. We set up another scope, forModel
, and use it to only pull in imports related to whichever model we're currently interested in. To make that work, we make sure the relevant model name gets passed through to our importer component.
Finally, we do a quick bit of testing by adding and removing a completed date, and by swapping out the model to make sure filtering is working exactly as we want. It's a quick, practical demo of how to use query scopes to keep your UI clean and focused on just the data you care about.