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-06-05 09:19:19 -07:00
2025-06-25 14:55:07 +01:00
2025-06-19 09:18:29 +00:00
2025-05-19 12:36:40 -03:00
2025-06-26 09:34:08 -04:00
2024-11-16 15:30:05 -05:00
2025-06-05 09:19:19 -07:00
2025-06-05 09:19:19 -07:00
2025-04-08 17:25:29 -03:00
2025-05-19 12:36:40 -03:00
2025-06-25 17:06:44 -04:00
2025-06-05 09:19:19 -07:00
2025-06-19 09:18:29 +00:00
2025-06-05 09:19:19 -07:00
2025-05-19 12:36:40 -03:00
2025-06-05 09:19:19 -07:00
2025-06-26 19:52:29 +00:00
2025-06-05 09:19:19 -07:00
2025-05-19 12:36:40 -03:00
2025-05-19 12:36:40 -03:00
2025-05-19 12:36:40 -03:00
2025-06-05 09:19:19 -07:00
2025-05-19 12:36:40 -03:00
2025-05-19 12:36:40 -03:00
2025-06-25 09:44:00 -04:00
2025-06-05 09:19:19 -07:00
2025-06-10 11:56:28 -04:00
2025-06-05 09:19:19 -07:00
2025-06-05 09:19:19 -07:00
2025-06-05 09:19:19 -07:00
2025-06-05 09:19:19 -07:00
2025-05-19 12:36:40 -03:00
2025-06-25 17:43:57 -07:00
2025-06-11 06:23:22 -07:00
2025-05-28 16:50:47 -03:00
2024-10-30 17:56:50 +00:00
2025-06-16 07:58:03 -04:00
2025-06-18 21:43:42 -07:00
2025-05-19 12:36:40 -03:00
2025-06-05 09:19:19 -07:00
2024-08-13 12:54:33 -04:00
2025-06-16 16:03:18 -04:00
2025-05-19 12:36:40 -03:00
2025-06-05 09:19:19 -07:00
2025-06-05 09:19:19 -07:00
2025-05-19 12:36:40 -03:00
2025-05-19 12:36:40 -03:00
2025-06-05 09:19:19 -07:00
2025-06-05 09:19:19 -07:00
2025-06-05 09:19:19 -07:00
2025-06-26 06:09:17 -07:00
2025-06-05 09:19:19 -07:00
2025-06-05 09:19:19 -07:00
2025-06-05 09:19:19 -07:00
2025-06-05 09:19:19 -07:00
2025-06-05 09:19:19 -07:00
2025-06-05 09:19:19 -07:00
2025-06-05 09:19:19 -07:00
2025-06-05 09:19:19 -07:00
2025-06-16 07:58:03 -04:00
2025-06-17 22:24:53 +00:00
2025-06-24 21:25:48 +03:00
2024-07-23 13:44:44 -04:00
2025-06-05 09:19:19 -07:00
2025-05-19 12:36:40 -03:00
2025-06-26 06:40:18 -04:00
2025-06-11 07:49:34 -07:00
2025-05-19 12:36:40 -03:00
2025-06-11 12:04:25 +00:00
2025-05-19 12:36:40 -03:00
2025-05-19 12:36:40 -03:00
2025-06-12 09:01:20 -04:00
2025-06-26 15:24:39 -04:00
2025-06-24 13:18:25 -04:00
2024-07-11 15:59:38 -04:00
2024-05-25 15:45:05 +00:00
2025-06-04 17:34:37 -03:00
2023-09-01 14:45:41 -04:00
2024-03-07 11:33:46 -05:00
2025-06-05 22:01:55 -03:00
2024-12-31 09:14:56 -05:00
2025-06-17 09:10:42 -04:00
2025-06-09 19:09:52 +00:00
2024-12-19 11:08:17 -05:00
2024-08-13 12:54:33 -04:00
2025-03-05 19:14:35 +00:00
2024-09-16 17:02:08 +00:00
2025-05-21 16:25:34 -04:00
2024-09-16 17:02:08 +00:00
2024-11-11 13:59:05 -05:00
2024-10-11 18:54:39 +00:00
2025-02-17 19:50:32 +00:00
2024-10-11 18:54:39 +00:00
2024-12-17 14:49:29 -05:00
2025-03-11 09:45:13 -06:00
2025-06-23 15:10:51 -04:00
2024-05-01 17:35:41 -04:00
2025-02-07 03:24:49 +00:00
2025-06-05 22:01:55 -03:00
2024-08-14 08:57:04 -04:00
2024-08-14 08:57:04 -04:00
2024-10-14 20:02:26 +00:00
2025-03-05 19:14:35 +00:00
2025-05-12 09:41:18 -04:00
2024-06-17 14:25:36 -04:00
2025-02-14 00:08:20 +00:00
2024-03-14 23:53:47 -04:00
2025-01-14 20:00:00 -03:00
2025-03-05 19:14:35 +00:00