Hey!
Letās say I have 2 models solution and feature. They offer a different set of blocks but both build pages with a url like client.com/slug (and not client.com/solution/slug).
So technically, it is possible to create a page in each model with the same slug.
When in SSR, there is no way to know which model to query from the slug. We can query both but if we get 2 results, we donāt know which one to display.
We could say it is poor CMS UX and that each model should have a different url prefix. I agree but I am working on a clientās website with a lot of pages and canāt change that easily.
Maybe this mistake should never leave the ādatoā side. We could imagine having a āroot level unique field slugā so that the CMS doesnāt allow saving a record if the slug is already in use even in another model. This might be a plugin? But Iām surprised it does not exist yet.
I am missing something? This feels weird to me, I have been working with Dato on a lot of different clients projects for 5+ years and donāt remember having this issue before.
The slug field is the slug you want to use on the website. It is required and unique.
The record_to_load field is a single-link field to either a solution or feature record. It is also required and unique.
Together, this should ensure that every slug links to only one record (of any type), and no record can have more than one slug.
Your frontend can just query the slug_list model to know which specific record to fetch.
It makes the query a tiny bit more complicated to set up, but hopefully not too bad, and it should help you more cleanly enforce this situation inside Dato?
As for the other topic/feature request for āunique field across all modelsā, it hasnāt gotten a lot of upvotes unfortunately (itās not a very common request), so itās not something weāve worked on yet.
Yes, you can write a plugin to do that, but I think it would be a bit janky (in terms of editor experience, since it would have to query all possible models in your project and then return a custom error message if it finds one). Probably using the built-in relationship, like above, would be a bit cleaner.
Hey @maxime.binet Iām Marcelo, Rogers colleague!
Another thing I wanted to mention is that most people that want a slug verification system on Dato do their own custom one with our plugin SDK with a private plugin. Since it is fairly easy to develop, and allows you to tailor the validation/slug formatting exact to the need of your specific routes, most companies end up going with the custom private plugin approach
A more general āglobal uniqueā validation would still be difficult, because thatās not something databases generally support⦠weād have to manually look up all the possible slug fields in all the possible models of your project and query them separately. Models can have more than one slug, and blocks can have their own slug fields. It turns the problem from a trivial āunique validation within this fieldā (which databases natively support) into a computationally expensive āunique across every slug field every record in this project and every nested block in each of those recordsā (a bunch of queries and indexing, and probably fragile). Itās also a difficult UI/UX problem because we donāt know which of all the possible slug fields are ārelatedā to the one youāre trying to test uniqueness on, so youād end up having to manually define a slug-to-slug cross-model relationship anyway, just in a more confusing way =/
When you manually define a relationship like in my example, however, then itās much easier on the system because it just uses normal database systems (check if this one field is unique, and then find me the related record).
By the way, I should mention that if you do choose to use that workaround, you can use inverse relationships to easily look up the contents of the related solution or feature record inside the same query!
Ok thatās really interesting and totally makes sense!
Iāll stick to the traditional ā1 model = 1 form of slugā and do my best to convince my client to follow this path.
Thanks for taking the time to go into such details