luckyframework / luckyframework/avram

Add named scope inversion with "not"

Open
#354 1 comment 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Crystal
Stars
183
Forks
67
PR merge metrics
No merged PRs in 30d

Description

I'm wanting to write a named scope like this:

```cr
class TaskQuery < Task::BaseQuery
def incomplete
completed_at.is_nil
end

def complete
not.incomplete
end
end
```

Is it possible to invert named scope results? Or is the best practice here to keep it explicit with completed_at.is_not_nil?

This is a relatively common convention for tracking boolean states with timestamps like approval, completion, acceptance, etc, so it'd be really handy to make that a touch easier!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing named-scope behavior from Task::BaseQuery and the incomplete/complete examples in the issue. Define done as a tested, supported way to invert a named scope with `not`, or a clear project-supported alternative if inversion is not intended.

Written by the indexing model from the issue text.

Assessment

Tech stack
crystal
Domain
database
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.