Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Wayne Godfrey 11 posts 42 karma points
    Nov 13, 2014 @ 21:27
    Wayne Godfrey
    0

    AncestorsOrSelf Order of Collection Members

    I recently upgraded a site from v6.1.6 to v7.1.8. I started seeing some weirdness on some of my pages and eventually found that something I was depending on in v6.1.6 had changed behavior.

    Specifically, I was using AncestorsOrSelf to get a collection of the nodes above the current page that were not of a particular document type and was then taking the last member of the collection.

    CurrentPage.AncestorsOrSelf().Where("nodeTypeAlias != \"DateFolder\"").Last().DocumentTypeAlias.ToString()
    

    This would give me the document type of ancestor node closest to the current page that was not of type "DateFolder".

    After upgrading to v7.1.8 this same line of code always returned the root node; in other words the node farthest away from the current page. If I changed the code to the following I got the closest node:

    CurrentPage.AncestorsOrSelf().Where("nodeTypeAlias != \"DateFolder\"").First().DocumentTypeAlias.ToString()
    

    Ignoring for a moment the fact that I shouldn't have been depending on the default order of the collection and should have been explicitly ordering by level, was this a known change somewhere between the v6.1.6 and v7.1.8?

    Thanks!

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Nov 13, 2014 @ 23:13
    Dennis Aaen
    0

    Hi Wayne,

    If I remember correctly then the nodeTypeAlias is changed to DocumentTypeAlias, in Umbraco 7.

    What if you do something like this does this do what you want.

    CurrentPage.AncestorsOrSelf().Where("DocumentTypeAlias != @0", "DateFolder").Last().DocumentTypeAlias.ToString()

    Hope this helps,

    /Dennis

  • Wayne Godfrey 11 posts 42 karma points
    Nov 15, 2014 @ 20:23
    Wayne Godfrey
    0

    Dennis,

    Thanks for the reply. I realize I wasn't clear on what my issue was.

    The syntax using nodeTypeAlias works; it's just that the order of the items in the collection appears to have changed from v6.1.6 to v7.1.8. Whereas before I had to use .Last(), I'm now having to use .First().

    Wayne

Please Sign in or register to post replies

Write your reply to:

Draft