Possible issue with IRelation Repository

Vote:
 

Hi there,

I have the following catalog three:

  • Root
    • Catalog
      • Pyjama - category
        • Shorts - category
      • Men - primary category of shorts
        • Shorts - category
          • TheBlueShort

When I call _relationRepository.GetParents<NodeRelation>(reference-to-shorts-category).ToList() I was expecting to get a reference to "Men" category since it's the parent and primary category of "Shorts", but it returns a reference to "Pyjama" which is an additional category. Is that correct? Am I doing anything wrong?

Thank you in advance!

#232969
Edited, Dec 02, 2020 17:56
Vote:
 

You probably need to use IsPrimary like in the below code snippt

var nodeRelations = _relationRepository.GetParents<NodeEntryRelation>(entryContentReference).ToList();

            var primaryRelation = nodeRelations.FirstOrDefault(x => x.IsPrimary);

            if (primaryRelation != null)
            {
                var thisRelationContentReference = _referenceConverter.GetContentLink(primaryRelation.Parent.ID, CatalogContentType.CatalogNode, primaryRelation.Parent.WorkID);
                var nodeContentBase = _contentLoader.Get<NodeContentBase>(thisRelationContentReference);
                return nodeContentBase.ContentLink;
            }
#249322
Feb 27, 2021 14:01
Vote:
 

My memory is a bit rusty but yes it is a known issue. That will only return the linked node. You need to get the node content and use ParentLink to get the true parent node. 
IsPrimary is only for node entry relation btw

#249360
Feb 28, 2021 15:58
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.