Nested Docs: Handling Slug Conflicts and Query Limitations

default discord avatar
livog
last month
1

Hey everyone šŸ‘‹,



I've been using the nested docs plugin with Payload CMS and it's left me with some questions about data structure. I have two main collections:

pages

and

recipes

. The

pages

collection resembles what we would typically see in WordPress. I've implemented nested docs on

pages

but I'm unsure about how to lock down the slugs so that

pages

can't create URLs that conflict with the

recipes

collection. For example, how can I prevent

pages

from creating any URLs with

/recipes

in the breadcrumbs?



On a related note, I've run into an issue when querying pages based on their breadcrumbs. I've tried querying like this:

/api/pages?where[breadcrumbs.url][equals]=%2Frecipes%2Fwith%2Fsugar

, but it doesn't solve the issue when multiple pages match parts of the query. I've considered adding a hidden

path

field that saves the last index of the breadcrumbs array, and populating it using a

beforeValidate

hook. Is this the right approach? Is there a way to ensure that this

path

doesn't collide with another collection's path before saving?



I've searched through the Discord and documentation, but I haven't found anything that addresses these issues. I’m relatively new to Payload but have a lot of experience with JavaScript. This specific issue is a bit of a snag for me, and I could really use some advice. We're anticipating our collection entities to reach around 30,000, and we want to prevent unexpected pages from being rendered.



Thanks in advance for your help! šŸ™

  • default discord avatar
    Zephury
    last month

    Did you ever figure out how you're going to handle these things? Going through some of the same thoughts myself right now.

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.