luckyframework / luckyframework/avram

Unable to use `only_kept` more than once in a query

Open
#726 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

https://github.com/luckyframework/avram/blob/1f0b0cd0bfd9e078dc0c05838f48958ba9713443/src/avram/soft_delete/query.cr#L18

This query returns the wrong SQL

User::BaseQuery.new.only_kept.hide(false).or(&.only_kept.featured(true))

Should return

SELECT * FROM users WHERE soft_deleted_at IS NULL AND hide = 'f' OR soft_deleted_at IS NULL AND featured = 't';

Actually returns

SELECT * FROM users WHERE hide = 'f' OR soft_deleted_at IS NULL AND featured = 't';

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 at src/avram/soft_delete/query.cr#L18 and reproduce the query shown in the issue. Compare the generated SQL with the expected SQL, then verify that using only_kept on both sides of the or condition preserves both soft_deleted_at IS NULL predicates.

Written by the indexing model from the issue text.

Assessment

Tech stack
crystal
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.