Replies: 7 comments 1 reply
-
This isn't going to work the way you intend. Search works off of the values in the database. You can't have a virtual field and search it. You could solve this by persisting the fullTitle and hide the field in the admin UI. // remove this
hooks: {
beforeChange: [
({ siblingData }) => {
delete siblingData['fullTitle']
}
],
// optional add:
admin: {
hidden: true,
}, I'm going to close this issue since there isn't anything to be done. Let us know if you have further questions. |
Beta Was this translation helpful? Give feedback.
-
Thank you for the information! I am actually not trying to search on the virtual field. I would only like to search on the This works perfectly when searching /collections/tracks, which is why I don't believe it would be bad practice necessarily. I have a large number of I could make Maybe using a virtual field is not the best way to do this, though. Is there a better way to change what is displayed as the text/title on the search results from the relationship field without changing which field(s) Payload uses to search? I don't believe I am able to reopen this issue myself and maybe this is just expected behavior, but it seems like a bug as the relationship field is not abiding by the Thanks again for your response! |
Beta Was this translation helpful? Give feedback.
-
@DanRibbens do you think I should create a new issue for this? Thank you! |
Beta Was this translation helpful? Give feedback.
-
Sorry I missed your comment from 2 weeks ago. We can revisit this. I need to make sure I understand it. |
Beta Was this translation helpful? Give feedback.
-
Thank you, I'm sure you're busy with the more pressing issues, so whenever you get around to it is totally fine by me! I'm happy to provide more info or code examples if helpful. Thanks again! |
Beta Was this translation helpful? Give feedback.
-
I converted this to a discussion because it is less a bug and more a question about how By name,
I had considered something with relationships but that won't work because using relationTo arrays would be messy to define which fields to search on and having this granularity on a field by field basis probably won't be helpful. What do you think? |
Beta Was this translation helpful? Give feedback.
-
Hi there, I'm encountering the same issue (virtual field as title gives issues for relationship) :
If I persist the virtual field used as a title all is fine.
Payload is making my life so much easier ;) The collection config
|
Beta Was this translation helpful? Give feedback.
-
Link to reproduction
No response
Describe the Bug
I have a collection called
tracks
which has a virtual field calledfullTitle
(which is used foruseAsTitle
) and regular field calledtitle
. I want to search thetitle
field, so I addedtitle
to thelistSearchableFields
array andindex: true
to thetitle
field. I am now able to search for tracks at /collections/tracks, but I cannot search for tracks to add whentracks
is a relationship field on a different collection calledsetlists
.When searching for tracks to add to the setlist relationship field
tracks
only about 10 tracks (the default min) show up and no more will populate when you begin typing.The issue seems to stem from the fact that the search on collections/track uses
where[or][0][title][like]=cat
and the search from the setlist relationship field useswhere[or][0][fullTitle][like]=cat
(which is the virtual field) for some reason.To Reproduce
useAsTitle
and a different field(s) inlistSearchableFields
Here are the collections I am using for reference:
Here is my
Track.ts
collection:and here is my
Setlist.ts
collection which usestracks
as a relationship field calledtracks
:Here are screenshots of the problem from the UI:
This first image is from /collections/tracks:
and this second is when I try to search for a track to add to a setlist:
As you can see, there should be at least 2 other tracks (besides "cat fancy" as it's already added) that show up for the setlist, but it shows no options.
As stated above, this is because the search on collections/track uses
where[or][0][title][like]=cat
and the search from the setlist relationship field useswhere[or][0][fullTitle][like]=cat
(which is the virtual field) for some reason.Payload Version
2.0.3
Adapters and Plugins
db-mongodb, bundler-vite, richtext-lexical
Beta Was this translation helpful? Give feedback.
All reactions