Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
A soft-delete filter must also exclude merged-away records
When entities can be merged, filtering live records requires checking both the delete flag and the merge pointer.
Bad example
| 1 | const matches = await db |
| 2 | .select() |
| 3 | .from(profiles) |
| 4 | .where(isNull(profiles.deletedAt)); |
Explanation (EN)
If merging two entities only stamps a 'merged into' pointer on the loser without also soft-deleting it, this query still returns the merged-away profile as if it were live, alongside its surviving counterpart under the same name.
Objašnjenje (HR)
Ako spajanje dva entiteta samo označi pokazivač 'spojeno u' na gubitniku bez da ga i soft-obriše, ovaj upit i dalje vraća spojeni profil kao da je aktivan, uz njegovog preživjelog dvojnika pod istim imenom.
Good example
| 1 | const matches = await db |
| 2 | .select() |
| 3 | .from(profiles) |
| 4 | .innerJoin(persons, eq(persons.id, profiles.personId)) |
| 5 | .where(and(isNull(profiles.deletedAt), isNull(persons.mergedIntoPersonId))); |
Explanation (EN)
Join to the parent entity and check its merge pointer as well as the delete flag, matching the convention already used elsewhere in the codebase for 'is this record actually live'.
Objašnjenje (HR)
Spoji na roditeljski entitet i provjeri njegov pokazivač spajanja uz zastavicu brisanja, u skladu s konvencijom koja se već koristi drugdje u kodu za 'je li ovaj zapis stvarno aktivan'.
Notes (EN)
When a 'live record' check already exists elsewhere in the codebase (e.g. in a repository method), reuse that exact predicate instead of re-deriving a partial version of it.
Bilješke (HR)
Kad provjera 'aktivnog zapisa' već postoji negdje drugdje u kodu (npr. u repository metodi), ponovno iskoristi taj točan predikat umjesto da iznova izvodiš njegovu djelomičnu verziju.