Copied to clipboard

Flag this post as spam?

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


  • Sidy Ndiongue 6 posts 54 karma points
    Nov 24, 2015 @ 04:00
    Sidy Ndiongue
    0

    Is the Model.Content.Id a good unique identifier

    Hi

    I was wondering if the Model.Content.Id field is a good unique identifier, will it ever change? The reason why I am asking this is because I am adding disqus comments onto my site and it requires a unique id.

    Thanks

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Nov 24, 2015 @ 05:04
    Nicholas Westby
    0

    It will not usually change under normal circumstances. Here are the scenarios I can think of that would cause it to change:

    • You migrate between two environments (e.g., staging to production) using Courier. While the underlying GUID remains the same, Courier may change the node ID.
    • You delete the node and then recreate it. This would be a new node, though it may in most other ways appear to be identical to the previous node.

    It might be worthwhile to intercept the node creation event and automatically populate an editable "Disqus ID" field. That way, if you ever need to recreate a node or if you migrate between environments, you could retain the same ID. That's probably overkill, as those situations are probably not likely an issue with most setups. Unless you are really worried, I'd just go with the node ID (as you have suggested).

  • Niels Hartvig 1951 posts 2391 karma points c-trib
    Nov 24, 2015 @ 06:16
    Niels Hartvig
    0

    It'll likely change if data is moved between environments, whether that's via Courier, Package installer or something similar. It won't change in the current environment.

  • Sidy Ndiongue 6 posts 54 karma points
    Nov 24, 2015 @ 12:32
    Sidy Ndiongue
    0

    Ok sounds good.

    Thanks

  • Sidy Ndiongue 6 posts 54 karma points
    Nov 25, 2015 @ 04:42
    Sidy Ndiongue
    0

    Maybe guid's would be a better idea. How do I retrieve the guid I can't seem to find it in the docs.

    Thanks,

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Nov 25, 2015 @ 04:53
    Nicholas Westby
    1

    Try this:

    var guid = Model.Content.GetKey();
    

    If you don't see that in intellisense, it may be because it's an extension method in Umbraco.Web.PublishedContentExtensions. As an alternative, this should also work:

    var guid = (Model.Content as IPublishedContentWithKey).Key;
    

    That is essentially what that extension method is doing.

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Nov 25, 2015 @ 05:00
    Nicholas Westby
    0

    By the way, this technique is apparently very new (just released on Umbraco 7.3.0): http://issues.umbraco.org/issue/U4-7038

    My guess is the old way was to use the content service to obtain the GUID. However, that hits the database. So I suppose the new addition allows for the GUID to be accessed from the cache rather than hitting the database.

    Also, one may be required to republish/rebuild/reindex for the new way of accessing the GUID to work (on installations that were upgraded from older version of Umbraco). Just thought I'd mention that in case somebody comes across this post in the future and it isn't quite working out for them.

  • Sidy Ndiongue 6 posts 54 karma points
    Nov 25, 2015 @ 05:04
    Sidy Ndiongue
    0

    Thank you very much, seems to solve my problem.

Please Sign in or register to post replies

Write your reply to:

Draft