Updating Category Name breaks link to collection item until item saved again

  • I have a set of news items and I'm using categories assigned to them. Changing the category name breaks the link to the articles when showing the collection based on category.


    I'm creating links to the categories at the foot of each article, the linking is dynamic and works from the catPath.

    Code
    1. <a href="/resources/news/categories/<perch:category id="catPath">"><perch:category id="catTitle"></a>

    When updating the category, say changing it's name - the category link on the article is updated fine both the path and title, when clicked the following page shows the correct category information however the previously associated articles don't show.


    Code
    1. perch_collection('News Articles', [
    2. 'category' => $newsCategory,
    3. 'template' => '_news/news_list.html',
    4. ]);


    The only way to get them to show again is to open and re-save each article - obviously I can't expect the client to do this.


    Am I missing something?

  • Yeah, tried that and it does not unfortunately.


    There is further odd unexpected behaviour:


    If the category is changed to a brand new name, the call show now articles.

    If the category is changed back to a name previously used the call works without having to resave.


    Perch showall shows the category id is still correct and does not change.


    It's almost like there is a cache somewhere that isn't being updated.

  • A reluctant workaround is to set the catSlug as indelible

    Code
    1. <perch:category id="catSlug" type="slug" for="catTitle" suppress="true" indelible="true"/>

    This way the slug gets set and never changes, therefore never breaking the link.


    The client can still change the title, but the catPath remains unchanged.


    I'd recommend doing this on the templates/categories/set.html template too.