File tree Expand file tree Collapse file tree 2 files changed +8
-4
lines changed
Sources/StructuredQueriesCore/Documentation.docc/Articles
Tests/StructuredQueriesTests Expand file tree Collapse file tree 2 files changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -477,11 +477,15 @@ RemindersList
477477 .select {
478478 Row.Columns (
479479 remindersList : $0 ,
480- milestones : #sql (" \( $1 .jsonGroupArray (filter : $1 .id .isNot (nil ))" ),
481- reminders: #sql(" \($2 .jsonGroupArray (filter : $2 .id .isNot (nil ))" )
480+ milestones : #sql (" \( $1 .jsonGroupArray (isDistinct : true , filter : $1 .id .isNot (nil ))" ),
481+ reminders: #sql(" \($2 .jsonGroupArray (isDistinct : true , filter : $2 .id .isNot (nil ))" )
482482 )
483483 }
484484```
485485
486+ > Note: Because we are now joining two independent tables to `RemindersList`, we will get duplicate
487+ > entries for all pairs of reminders with milestones. To remove those duplicates we use the
488+ > `isDistinct` option for `jsonGroupArray`.
489+
486490This will now load all reminders lists with all of their reminders and milestones in one single
487491SQL query.
Original file line number Diff line number Diff line change @@ -214,9 +214,9 @@ extension SnapshotTests {
214214 assertQuery (
215215 RemindersList
216216 . group ( by: \. id)
217- . leftJoin ( Reminder . incomplete) { $0. id. eq ( $1. remindersListID) }
218217 . leftJoin ( Milestone . all) { $0. id. eq ( $2. remindersListID) }
219- . select { remindersList, reminder, milestone in
218+ . leftJoin ( Reminder . incomplete) { $0. id. eq ( $1. remindersListID) }
219+ . select { remindersList, milestone, reminder in
220220 RemindersListRow . Columns (
221221 remindersList: remindersList,
222222 milestones: #sql(
You can’t perform that action at this time.
0 commit comments