Copied to clipboard

Flag this post as spam?

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


  • Pavel Gurecki 55 posts 158 karma points
    Jun 27, 2014 @ 10:19
    Pavel Gurecki
    0

    AncestorOrSelf() returns self - should be Breaking Change - upgrading v6 to v7

    Hello,

    I've bumped into a small issue while upgrading from v6 to v7 - AncestorOrSelf() (no parameters) now returns the node itself and not the root node as it was before - this breaks all my templates as I have been using AncestorOrSelf() as main method to get root node. 

    To be version specific - I am updating from v6.1.3 to v6.2.1 then to v7.1.4 . I didn't find any related breaking change in versions specific lists from 6.1.3 to 7.1.4. Maybe i am missing something, but if not - it definitely should be there. 

    When browsing Umbraco source, I found that this change was introduced in v6.2.0:

            // note: that one makes no sense and should return self -- but fixing that
            // would be a breaking change. Defining FIX_AXES would fix the situation.
            public static IPublishedContent AncestorOrSelf(this IPublishedContent content)
            {
    #if FIX_AXES
                return content;
    #else
                return content.EnumerateAncestors(true).FirstOrDefault(x => x.Level == 1);
    #endif
            }

    As comment states, "#if FIX_AXES" should fix that. Maybe it fixes for v6 (haven't tested), but not for v7.1.4.

  • Sebastiaan Janssen 5045 posts 15476 karma points MVP admin hq
    Jun 27, 2014 @ 10:41
    Sebastiaan Janssen
    0

    This code is still the same in 7.1.4 so I don't know what happened. We don't compile with FIX_AXES turned on so that's not it.

  • Pavel Gurecki 55 posts 158 karma points
    Jun 27, 2014 @ 10:51
    Pavel Gurecki
    0

    I have also made a fresh install of v7.1.4 downloaded from http://our.umbraco.org/contribute/releases/714  - AncestorOrSelf() also returns self, so it is not a problem with upgrade. 

  • Sebastiaan Janssen 5045 posts 15476 karma points MVP admin hq
    Jun 27, 2014 @ 11:26
    Sebastiaan Janssen
    0

    What does your content tree look like and on which page in that content tree are you calling AncestorOrSelf() ?

  • Pavel Gurecki 55 posts 158 karma points
    Jun 30, 2014 @ 09:34
    Pavel Gurecki
    0

    Tested it on TXT starter kit in news page:

     

    • Home
    • -- News
    • ---- Test page

     

    @CurrentPage.AncestorOrSelf().Name outputs "Test page"

     

  • Bilal Isa 60 posts 76 karma points
    Jun 30, 2014 @ 11:59
    Bilal Isa
    0

    Hi Pavel,

    Can you provide an example of how you're using the method?

    Kind regards, Bilal

  • Pavel Gurecki 55 posts 158 karma points
    Jun 30, 2014 @ 13:02
    Pavel Gurecki
    0

    Hi Bilal,

    I get current site root node in my templates like this:

    var rootNode = Model.Content.AncestorOrSelf();

     

    Now I need to use Model.Content.AncestorOrSelf(1) 

Please Sign in or register to post replies

Write your reply to:

Draft