How to search collection that has a relationship element content in rich text field? #852
-
I am implementing a feature to get all other entries that has a relationship link to current entry. For example I have an author collection and an article collection. The article has a relationship field author. This feature shows how many articles are using this author instance as their relationship field author's value. In fact I using the rest api But if I use a relationship in rich text that link to the author. Then how to search the collection that its rich text field has a relationship link to the author_id? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
Hey @EasonSoong — You should be able to do this with something like:
Rich text fields can be queried on just like any other field, so give that a shot! |
Beta Was this translation helpful? Give feedback.
-
Hello @jmikrut , I tried this feature in the newest payload version. And it works when I trying to search relationship in a rich text field. Thanks you for that! // I have a article collection which use a block field
export const Articles: CollectionConfig = {
fields: [
{
name: 'content',
type: 'blocks',
blocks: [Content, Media, Button],
},
]
};
// And the Content block has a rich text field
export const Content: Block = {
fields: [
{
name: 'richText',
type: 'richText',
}
],
};
// My saved data in database
{
content: [{
blockType: "content",
id: "62e63a7bc3b0131e1b5d53a9",
richText: [{
children: [{text: ''}],
relationTo: "authors",
type: "relationship",
value: { id: "rich-text" }
}]
}]
} My search api: When I try to search relationship in rich text content from block field, the return result of buildQuery still ignore my path after content. Could you help to check this? |
Beta Was this translation helpful? Give feedback.
Hey @EasonSoong —
You should be able to do this with something like:
Rich text fields can be queried on just like any other field, so give that a shot!