Copied to clipboard

Flag this post as spam?

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


  • Ryan 24 posts 106 karma points
    Jul 05, 2017 @ 02:43
    Ryan
    1

    Help me understand Umbraco Relations

    Hi, I have recently discovered Umbraco Relations in the developer tab / api and how useful and powerful they can be. However I have a couple of immediate questions after reading what I can find on the topic:

    1. Why is there a member type, but no "User" type? In my situation I thought it would be nice to use this system to create multi-user approvals of documents, but I need to work around that by creating a document which effectively marks the approval and relate the two documents. Is there a technical reason or little demand for lifting this limitation?

    2. When I create a "relation type" under the developer tab, is that a kind of "template" for creating specific relationships using the code api? Is the only place where relationships be used with code?

    3. If I delete one of the items which have a relation on them, is the relation automatically deleted (cascade delete), or do I need to hook this application event and delete it myself? What about if I just trash the item, does the link remain?

  • Ryan 24 posts 106 karma points
    Jul 05, 2017 @ 03:54
    Ryan
    1

    I've been doing some experimentation and so far I've mostly discovered the answers to #2 and #3:

    2

    Yes, they are a kind of template. The actual relationships are created, managed, and used in code (they are only able to be viewed through each relation type under the developer section).

    3

    When a specific relationship is created (with code, or by copying a document and relating to original), and then an item in that relationship is moved to the recycle bin, the relationship still stands. When the item is then permanently deleted from the recycle bin, the relationship is automatically deleted too. I like this feature of Umbraco!

  • Jeffrey Schoemaker 408 posts 2138 karma points MVP 8x c-trib
    Jul 05, 2017 @ 05:38
    Jeffrey Schoemaker
    1

    Hi Ryan,

    Relations in Umbraco are there to relate two types of data to each other. That could be node-to-node, node-to-user, member-to-user, user-to-media, media-to-node, etcetera.

    One of the built-in default relations is when you copy a node. There's a checkbox that says "Relate to original":

    enter image description here

    Other images you'll have to define for yourself, and I don't think the backoffice is the best way to do that, because it's pretty limited. Instead you could go to the database and look for the table umbracoRelationType. There you can see which type of data could be related to which type of data. And you could also specify whether it's bidirectional (parent-child, or also child-parent).

    Relations have to be created via code and you can always add in a comment to add an extra dimension to your relationship :). These are stored in the table umbracoRelation and in the field comment you can drop extra data you want to store about the relation.

    The documentation is a bit lacking on our, but I think this is still a good starting point, although the blog post is almost 5 years old; https://umbraco.com/blog/getting-to-know-umbraco-relations/.

    Hopefully it helps,

    Jeffrey

  • Ryan 24 posts 106 karma points
    Jul 05, 2017 @ 07:49
    Ryan
    0

    Thanks for your reply. When you say the backoffice is pretty limited, do you know of any ways of extending it in the area of relations? I'd like to create content nodes and relations from my custom listview, but the api here doesn't look like it supports creating relations, and for that matter creating content https://our.umbraco.org/apidocs/ui/#/api/umbraco.resources.relationResource

    Do you know of a way to call through to the C# backend for such functionality?

    Also for node-to-user I don't see a user option in the relation type dropdown for user, is a user just the same as a document?

  • Jeffrey Schoemaker 408 posts 2138 karma points MVP 8x c-trib
    Jul 05, 2017 @ 08:48
    Jeffrey Schoemaker
    0

    Hi Ryan,

    limited in the way that you cannot create relations with different types of data (like user or media). There's no dropdown in the UI for switching it to user. Unfortunately for now you'll have to update this in the database :(

    You're currently looking at the wrong documentation. This is the correct one: https://our.umbraco.org/documentation/reference/management/services/relationservice.

    And there you can find the correct options to make C# calls.

    If you still have questions please let me know.

  • Ryan 24 posts 106 karma points
    Jul 05, 2017 @ 09:14
    Ryan
    0

    Ahh I see. Would you recommend just doing a REST call to a backoffice UmbracoApiController and then doing what I need from there? EDIT: This looks promising? https://github.com/umbraco/UmbracoRestApi

    For creating the link to a user in the database, do I need to create a relationType template using the GUID for User or can I get away with skipping this step and storing a blank type alias if I just need to query relations by parent and child ids? EDIT: Users dont actually seem to be an object and thus there is no GUID for them according to this list https://our.umbraco.org/apidocs/csharp/api/Umbraco.Core.Constants.ObjectTypes.html

  • Ryan 24 posts 106 karma points
    Jul 09, 2017 @ 06:50
    Ryan
    0

    I'm still yet to figure out how to link to a User. From the best of what I can gather studying the source code, Umbraco seems to not store any entity related to user. The tree in the backoffice is simply enumerating the ASP.Net Identity users. For now I'm just going to store document nodes that have a user picker in their doctype since I have other information to include with the link. It would be pretty awesome if backoffice users were supported in Umbraco Relations.

  • Dimitris Chrysomallis 23 posts 137 karma points
    Oct 19, 2017 @ 12:53
    Dimitris Chrysomallis
    0

    I would also like to know in what ways the Relations API can implement useful functionality. The way documents and properties play together allows for building a hierarchy which you can then query in your templates through Linq.

    I suppose, adding the Relations dimension allows for a more relational model to creep in, in addition to how your document types have been defined in the backend. Is this correct?

    Also, has anyone used Relations to solve a particular problem that is not covered by the default content model (e.g extracting related pages in another language)?

  • Jeffrey Schoemaker 408 posts 2138 karma points MVP 8x c-trib
    Oct 19, 2017 @ 13:36
    Jeffrey Schoemaker
    1

    Hi Dimitri,

    we use it especially when different types of data needs to be related. For example relate a mediaitem to a contentitem, or a member to content, or a member to other members.

    In one of our projects we've used relations to store which matching score one member had to another member.

    Those situations could be useful and cannot be directly stored in the tree.

  • Dimitris Chrysomallis 23 posts 137 karma points
    Oct 19, 2017 @ 14:14
    Dimitris Chrysomallis
    0

    Hi,

    So am I right to assume that the appropriate context to Relate() nodes is with event handlers, and then GetBy...() in your templates/controllers?

  • Jeffrey Schoemaker 408 posts 2138 karma points MVP 8x c-trib
    Oct 19, 2017 @ 14:26
    Jeffrey Schoemaker
    0

    Yes, indeed. Or in your other code (not per se only in event handlers)

Please Sign in or register to post replies

Write your reply to:

Draft