feat: select fields
- [x] generate types for the
selectproperty - [x] infer the return type by
selectwith 2 modes - include (field: true) and exclude (field: false) - [ ] lots of integration tests, including deep fields / localization etc
- [ ] implement the property in db adapters
- [ ] docs
Do you want to fix the failing build before or after we review this?
I have some issues when types aren't generated (when the code inside of packages/, not test/), trying to resolve it and then the build should be fixed
Does this work on fields from related documents (relationship fields). For example, usually I only want a few fields from an image relationship.
We will implement soon exactly what you described in a separate PR. This is just the basement
🚀 This is included in version v3.0.0-beta.121
How can we target a field within an array? For example, if we have:
{ name: 'items', type: 'array', fields: [ { name: 'title', type: 'text' }, { name: 'text', type: 'text' } ] }
How can we exclude the text field from each item in the array?
How can we target a field within an array? For example, if we have:
{ name: 'items', type: 'array', fields: [ { name: 'title', type: 'text' }, { name: 'text', type: 'text' } ] }How can we exclude the text field from each item in the array?
This will work, I'd recommend you to generate types as it provides autocompletion for that if you haven't already
select: {
items:{
title: false
}
}
But it doesn't affect the return type for typescript if the field is nested.
Ahh, I used an array thinking it was a simple example. That does indeed work, but I have a blocks field and want to select out some fields in a blockOptions group that all blocks will have. Would it be possible to have the defaultPopulate property on groups, arrays, and blocks?
Also, as an aside, I'm running beta.123 with generated types and am not getting any autocompletion.
Possible
select: {
blocks: {
cta: { // blockType here
text: false // exclude text from blocks within the "cta" blockType
}
}
}
Also, as an aside, I'm running beta.123 with generated types and am not getting any autocompletion.
This is interesting because it works in our tests. I'll look into this
Okay, I think I understand the problem
Can you try to temporary disable strict: true or strictNullChecks: true in your tsconfig? It should work then
Then, after 124 beta you can re-enable it again.
Fixed here https://github.com/payloadcms/payload/pull/8991 thanks for the report I didn't notice this
Also, I forgot to mention that you can just remove ?
from this (and globalsSelect if you wish)
in your
payload-types.ts, so it'll be required