Relations support
not-vainglorious opened this issue ยท 3 comments
I made my own plugin for nextjs revalidation and got some your ideas but with improvements. I added support to relations and if you like to see it I can extend your logic and create new pull request for this feature.
Should mention that it will work a bit different. I will use custom back-end endpoint which will redirect to correct url because i'm using strapi metadata to verify all things and define correct populates and requesting entity by one single request. Also this one works only with manyToOne
and oneToOne
.
As example this works like this:
{
uid: 'api::building.building',
query: {
city: '{neighbourhood.city.slug}',
neighborhood: '{neighbourhood.slug}',
building: '{slug}',
},
},
Also when path ends with relation and not common field you will just get id so {neighbourhood.city}
will add related city id to the query.
Reply to issue if you like it and i will make PR for this one.
Hi @not-vainglorious I figured supporting relations would involve some extra API calls in the content manager ๐๐ป And yes I agree only manyToOne
and oneToOne
relations would be supported.
Happy to start working on a PR with you! ๐
@not-vainglorious The preview button plugin has recently updated to v1.1.1 with a new feature to use a plugin/preview-button/before-build-url
hook to modify the preview URL in a more advanced way. This should make it easy to populate relation data into the URL ๐๐ป
See the Extending section of the README for full details.
Hello @mattmilburn I want to create a custom url for preview button based on selected relation.
I tried extending the plugin as per your README but the hook is not working. Followed each steps just like it is mentioned.
The URL I want is https://sitename.com/page/{relation.fieldName}/{slug}. Can you please help me with a demo.
Thanks