Product Updates

DatoCMS changelog for new features and general improvements
New UI Improvement

More fine grained controls on publishing/unpublishing of linked records

May 6th, 2021

It's no doubt that having a strongly linked content schema helps you find the information you need, when you need it. But what happens when we attempt to (un)publish or delete interconnected resources?

Most CMSs are terrible at handling this sort of thing. Contentful for example simply leaves a ghost references to a records that no longer exists, and calls it a day. Their philosophy seems to be "users will take care of filtering this garbage somehow on the frontend, not our problem!".

What distinguishes us the most from competition is a greater care in keeping the saved contents coherent and always consistent. It is our problem to ensure that, not yours. You've better things to do.

Today, we're happy to introduce additional settings that allow you to specify exactly what behavior to adopt when such events occur. And since different settings may make sense depending on the specific context, you can specify different behaviours for every Link, Links and Structured Text in your project.

If you have ever worked with databases, you will surely notice a similarity with the DELETE CASCADE settings that you can set on the foreign keys of a table:

With this change, editors won't have to guess the right pattern to solve intricate cases of dependencies between records, since the developers have already taken care of that for them. And scheduled publish/unpublish operations will be much more secure and deterministic than before.

The default settings you'll find in the existing fields are the ones that were in place until now, so don't worry, nothing will change unless you decide to do so.

If you want to massively change these settings, you can conveniently do so via the Content Management API and migrations.

In this example, we're changing settings for every Link, Links and Structured field in a project, so that when a publishing is requested and a field references some unpublished records, the resolution strategy is to also publish the referenced records:

1
module.exports = async (client) => {
2
const itemTypes = await client.itemTypes.all();
3
4
for (const itemType of itemTypes) {
5
const fields = await client.fields.all(itemType.id);
6
7
const interestingFields = fields.filter((f) =>
8
['link', 'links', 'structured_text'].includes(f.fieldType),
9
);
10
11
for (const field of interestingFields) {
12
const validatorFor =
13
field.fieldType === 'link'
14
? 'itemItemType'
15
: field.fieldType === 'links'
16
? 'itemsItemType'
17
: 'structuredTextLinks';
18
19
if (
20
field.validators[validatorFor]
21
.onPublishWithUnpublishedReferencesStrategy !== 'publish_references'
22
) {
23
await client.fields.update(field.id, {
24
validators: {
25
...field.validators,
26
[validatorFor]: {
27
...field.validators[validatorFor],
28
onPublishWithUnpublishedReferencesStrategy:
29
'publish_references',
30
},
31
},
32
});
33
}
34
}
35
}
36
};
Start using DatoCMS today
According to Gartner 89% of companies plan to compete primarily on the basis of customer experience this year. Don't get caught unprepared.
  • No credit card
  • Easy setup
Subscribe to our newsletter! 📥
One update per month. All the latest news and sneak peeks directly in your inbox.
support@datocms.com ©2024 Dato srl, all rights reserved P.IVA 06969620480