Said Akhrarov
605c993bb7
fix(drizzle): skip column if undefined in findMany (#12902)
<!--
Thank you for the PR! Please go through the checklist below and make
sure you've completed all the steps.
Please review the
[CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md)
document in this repository if you haven't already.
The following items will ensure that your PR is handled as smoothly as
possible:
- PR Title must follow conventional commits format. For example, `feat:
my new feature`, `fix(plugin-seo): my fix`.
- Minimal description explained as if explained to someone not
immediately familiar with the code.
- Provide before/after screenshots or code diffs if applicable.
- Link any related issues/discussions from GitHub or Discord.
- Add review comments if necessary to explain to the reviewer the logic
behind a change
### What?
### Why?
### How?
Fixes #
-->
### What?
This PR fixes an issue where sorting on a traditional virtual field with
`virtual: true` while using a drizzle-based db adapter would cause a
runtime error.
### Why?
To skip attempting to sort virtual fields which are not linked to a
relationship/upload and prevent a runtime error from surfacing.
### How?
Skipping the deletion of the property from the `selectFields` object if
the column is false-y.
Fixes #12886
Before:
[sort-virtualfield-drizzle-error.mp4](https://private-user-images.githubusercontent.com/78685728/457602747-b8661e47-a1a8-4453-b2ec-b7e7199b9846.mp4?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NTA2OTU0NzksIm5iZiI6MTc1MDY5NTE3OSwicGF0aCI6Ii83ODY4NTcyOC80NTc2MDI3NDctYjg2NjFlNDctYTFhOC00NDUzLWIyZWMtYjdlNzE5OWI5ODQ2Lm1wND9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTA2MjMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwNjIzVDE2MTI1OVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTE3NmMzOWI5YjNiNzEwYzk3ZWUyNDllYTBjMzZkNzkzMjhjNzc5YzJhNDlkOTBiNDk5MDFhMTdmNDA4NjJhZWQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.N1GJsiI_gZ8M54VHCAmiPEhcJGqRw3Ucy-VeM5R7UFE)
After:
[virtualfields-sort-Posts---Payload.webm](https://github.com/user-attachments/assets/f5a15d98-4a40-4817-bc6a-415f3ec27484)
<details>
<summary>Collection config used above</summary>
```ts
export const PostsCollection: CollectionConfig = {
slug: postsSlug,
admin: {
useAsTitle: 'title',
defaultColumns: ['title', 'exampleField'],
},
fields: [
{
name: 'title',
type: 'text',
},
{
name: 'exampleField',
type: 'text',
virtual: true,
admin: {
readOnly: true,
},
hooks: {
afterRead: [({ data }) => data?.title],
},
},
{
type: 'relationship',
name: 'category',
relationTo: 'categories',
},
{
name: 'categoryTitle',
type: 'text',
virtual: 'category.title',
},
],
}
```
</details>
---------
Co-authored-by: Sasha <64744993+r1tsuu@users.noreply.github.com>
2025-06-26 19:52:29 +00:00
..
2025-03-31 15:45:02 +00:00
2025-06-26 19:52:29 +00:00
2025-06-09 19:09:52 +00:00
2025-06-24 21:25:48 +03:00
2025-06-16 16:03:35 -04:00
2025-05-19 08:14:20 +00:00
2025-06-16 16:03:35 -04:00
2025-06-16 16:03:18 -04:00
2025-05-15 16:48:41 -04:00
2025-05-19 08:14:20 +00:00
2025-05-19 08:14:20 +00:00
2025-05-19 08:14:20 +00:00
2025-03-17 23:48:35 -04:00
2025-05-19 08:14:20 +00:00
2025-05-19 08:14:20 +00:00
2025-04-17 13:55:12 +00:00
2025-05-19 08:14:20 +00:00
2024-12-18 22:43:37 -05:00
2025-05-19 08:14:20 +00:00
2025-06-09 14:38:07 -04:00
2024-09-03 11:19:19 -04:00
2025-03-24 09:49:30 -04:00
2024-11-25 10:28:07 -05:00
2024-12-18 22:43:37 -05:00
2024-09-03 11:19:19 -04:00
2025-03-24 09:49:30 -04:00
2024-12-18 22:43:37 -05:00
2025-05-19 08:14:20 +00:00
2025-05-05 09:11:10 -04:00
2025-04-03 02:33:34 +03:00
2024-12-18 22:43:37 -05:00
2025-04-03 02:33:34 +03:00
2025-05-22 13:30:29 -04:00
2024-08-29 02:35:17 +00:00
2024-12-19 22:34:52 +00:00
2025-06-16 16:03:35 -04:00
2025-05-19 08:14:20 +00:00
2025-05-19 08:14:20 +00:00
2025-03-31 13:06:05 -06:00
2025-05-19 08:14:20 +00:00
2025-05-19 08:14:20 +00:00
2025-05-19 08:14:20 +00:00