Add link_set for updating links on StandardEdition update [WHIT-2828]
#10945
+18
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What
link_settoConfigurableDocumentLinkspatch_linksinPublishingApito calllink_set(if presenter has method defined)Why
A support ticket came in that raised an issue of associations persisting across the different types of News Article. This is because when a draft edition is updated, the
PATCHendpoint for links is called. This creates alink_setof thelinksof the edition. The creation of thelink_setmeans that even if subsequentPUTrequests are made with a new set oflinks, thelinksassociated with thelink_setof the document will persist. Therefore we need to include empty array for each association that the document does not utilize. When we do this, the association will be cleared from the content item and so can't be accessed by the frontend rendering applications.Implementation details
I did try and destructively remove the associations on the edition itself. The problem with this though is that an association can have a different name to how it is called on the edition.
ministerial_rolesisrole_appointments, so without some of way of mapping the name change there wasn't a way to do this programmatically.Personally, I quite like the non-destructive approach since it means the document can be switched back and forth and not need to be refilled in again.
This application is owned by the Whitehall Experience team. Please let us know in #govuk-whitehall-experience-tech when you raise any PRs.
Follow these steps if you are doing a Rails upgrade.