fix(drizzle): coalesce jsonb_agg/json_group_array to empty array for hasMany select join-where#16759
Open
GeorgS wants to merge 1 commit into
Open
Conversation
…hasMany select join-where
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Fix sub-folders not showing up in the folder browser (e.g. "Browse by folder" drawer) when those folders have no
folderTypeset (universal folders).Why?
Universal folders have zero rows in the
payload_folders_folder_typejoin table. Indrizzle/find/traverseFields.ts, the subquery that aggregates hasMany select field values usesjsonb_agg()(PostgreSQL) /json_group_array()(SQLite). When there are zero rows, these aggregates returnNULL— not an empty array. The subsequent JSON path checkNOT jsonb_path_exists(NULL, '$[*]')evaluates toNULLin SQL (notTRUE), so theWHEREclause silently excludes universal folders from the results.This affects any query using
exists: false(or any other operator) on ahasManyselect field used inside a polymorphic joinwhereclause.How?
Wrap both aggregate subqueries in
COALESCEso they always return an empty array instead ofNULLwhen no rows exist:This should also be backported to v3
Fixes #14821