Copied to clipboard

Flag this post as spam?

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


  • greengiant83 88 posts 109 karma points
    Mar 16, 2011 @ 21:50
    greengiant83
    0

    How to get Document's Parent's Document Type Alias

    I want to walk up a Document's parent tree looking for one of a certain DocumentType. Document's Parent property is a CMSNode object which doesn't seem to have anything indicating what document type it is.  Is there a way to find the Parent's document type alias without having to instantiate a new Document with the parent's id and incurring another big database call?

  • Harald Ulriksen 207 posts 249 karma points
    Mar 17, 2011 @ 08:39
    Harald Ulriksen
    0

    As I wrote in another answer, you should not use document unless you need to change something on it. Do the tree walking using nodefactory and only instantiate a document when you're certain you will change the data in it. 

     

  • greengiant83 88 posts 109 karma points
    Mar 17, 2011 @ 15:24
    greengiant83
    0

    Harald,

    For certain parts of my application I need to get at the latest saved content. As I understand it using the nodefactory node's limits you to only published content.  If there is a way to get saved content via the nodefactory I would much prefer to go that route.  Is there a way to do that?

  • Jonas Eriksson 930 posts 1825 karma points
    Mar 17, 2011 @ 15:34
    Jonas Eriksson
    0

    Hi, use documents for that (slower than nodefactory since it's using db call(s) for each doc):

    http://our.umbraco.org/wiki/reference/api-cheatsheet/enumerating-documents

    (.Parent works too)

    HTH / Jonas

  • greengiant83 88 posts 109 karma points
    Mar 17, 2011 @ 15:38
    greengiant83
    0

    Document.Parent is a CMSNode and not a Document. So the only way I see to do it is: new Document(myDoc.Parent.Id).ContentType.Alias.  This is functional but I plan on using this to walk up the document tree searching for a document of a certain type so I am hoping there is a way to do this without having to instantiate a whole new Document since it incurrs a fairly expensive DB call. 

  • Harald Ulriksen 207 posts 249 karma points
    Mar 17, 2011 @ 15:58
    Harald Ulriksen
    1

    Dear Mr. Green Giant (how do one address anyone with such name? ;-) )

    yes, if you work with unpublished content you will need to use the document tree. But, if this happens fairly often I think that you can benefit from writing your own stored procedure to locate the document you need and then load it as a document based on the id, rather than loading documents until you find the one you're looking for.

    If creating your own sql statement to find the documents might be an option then I can recommend http://blog.hendyracher.co.uk/wp-content/uploads/Umbraco-Schema-with-Constraints-v2.gif. For a full diagram see http://www.farmcode.org/post/2010/06/15/Umbraco-41-Database-Structure.aspx

    Cheers,
    Harald

Please Sign in or register to post replies

Write your reply to:

Draft