Is this a bug - CategoryIDPath

Jay Heavner asked on March 16, 2016 20:17

A repeater control with a filter the Category name property resolves to SQL That uses the field CMS_Category.CategoryIDPath. CategoryIDPath is derived from CategoryID which is an identity column. Identity columns do not sync with the same values but use the next available value in the pattern. That means that if categories are not identical across all synced environments then the IDs will not match across environments. I believe this is why Kentico uses GUIDs, to ensure consistency across environments.

Seems like the issue could be resolved by replacing the reference to CategoryIDPath with a reference to CategoryNamePath.

Here's the (simplified) SQL the Repeater generated with a specified Category. Note the usage of CategoryIDPath.

SELECT TOP 5 *, Date AS [CMS_O1], ROW_NUMBER() OVER (ORDER BY Date DESC) AS [CMS_SRN], 0 AS [CMS_SN], ''cms.document.cta.blogarticle'' AS [CMS_T]
FROM View_CMS_Tree_Joined AS V WITH (NOLOCK, NOEXPAND) INNER JOIN cta_BlogArticle AS C WITH (NOLOCK) ON V.DocumentForeignKeyValue = C.BlogArticleID AND V.ClassName = N''cta.BlogArticle'' LEFT OUTER JOIN COM_SKU AS S WITH (NOLOCK) ON V.NodeSKUID = S.SKUID
WHERE [NodeSiteID] = @NodeSiteID AND ([NodeAliasPath] LIKE @NodeAliasPath AND (
DocumentID IN (
SELECT DocumentID FROM CMS_DocumentCategory WHERE CategoryID IN(
SELECT **CategoryID** FROM CMS_Category 
WHERE CategoryIDPath LIKE ''/00000010%'' AND CategoryEnabled = 1 AND (NOT EXISTS(SELECT CategoryID FROM CMS_Category AS pc WHERE (pc.CategoryEnabled = 0) AND (CMS_Category.CategoryIDPath LIKE pc.CategoryIDPath+''/%'')))))) AND [DocumentCulture] = @DocumentCulture)

Recent Answers

David te Kloese answered on March 17, 2016 02:20


The usage of ID's in Kentico has some history and Kentico is moving more and more towards the usage GUID columns. Apparently that's not been done (yet) in this case.

If your values don't match with other environments and you really need to define this category you could try using a macro like:

{% GlobalObjects.Categories.Where("CategoryName='CodeNameOfTheCategory'").IDs %}

or if site specific

{% SiteObjects.Categories.Where("CategoryName='CodeNameOfTheCategory'").IDs %}

This will select the Category object ID, not sure why its called IDs (sounds plural).

Remember though to apply some sort of caching to this repeater since this macros isn't very efficient and perhaps check if the category is found.

Hope this points you in the right direction.



1 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.