-
Notifications
You must be signed in to change notification settings - Fork 811
Update the Relations article #6387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
a33bbcb
119a62e
7e98954
dffb87d
1a035a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
description: What are relations, how to create and manage them | ||
description: Learn about relations and how to create and manage them. | ||
--- | ||
|
||
# Relations | ||
|
@@ -8,69 +8,42 @@ Umbraco sections are built around the concept of 'trees' and there is an implici | |
|
||
 | ||
|
||
We refer to these relationships in the manner of a 'Family Tree' - eg, One content item might be the 'Parent' of some content items, and those content items would be referred to as the 'Children' of that parent. Items within the same branch of the tree can also be described as 'Ancestors' or 'Descendants' of an item, depending if they are above or below them in the depth of the tree. | ||
We refer to these relationships in the manner of a 'Family Tree'. One content item might be the 'Parent' of some content items, and those items would be referred to as the 'Children' of that parent. Items within the same branch of the tree can also be described as 'Ancestors' or 'Descendants' of an item. | ||
|
||
There are methods in Umbraco to support querying content items by their relative position in the tree to the current page using these concepts, eg `Model.Ancestors()` or `Model.Children()` or `Model.Descendants()` - but what about 'Cousins'? | ||
There are methods available to support querying content items by their relative position to the current page. This is possible using the following concepts: `Model.Ancestors()`, `Model.Children()` or `Model.Descendants()`. | ||
|
||
What if there are no direct Parent/Child/Ancestor/Descendant relationships between two items in a tree, but they are still somehow 'related' in the context of your website? For example, the alternate language translation pages of a content page. | ||
In some cases there are no direct relationships between two items in a tree, but they are still somehow 'related'. This could be the alternate language translation pages of a content page. | ||
|
||
What if there is also a 'relation' between different types of Umbraco entities in your site, eg Content -> Member or Member -> MediaFolder? Perhaps, you'd like to be able to retrieve and display the uploaded images from a specific logged-in Member. | ||
In other cases there is a 'relation' between different types of entities. This could be a relation between Content and Member, or Member and MediaFolder. You might need to be able to retrieve and display the uploaded images from a specific logged-in Member. | ||
|
||
These are the scenarios where the concept of **Umbraco Relations** provides a solution. | ||
|
||
## The Concept of Umbraco Relations | ||
|
||
Umbraco Relations allow you to relate almost any object in Umbraco to almost any other Umbraco object - under a defined _Relation Type_. | ||
Umbraco Relations allow you to relate almost any object in Umbraco to almost any other Umbraco object. This is done by defining a new _Relation Type_. | ||
|
||
### How is this different to pickers? | ||
|
||
With a Content/Member/Media picker that you might add to a Content Type - the relationship is ONLY 1-way. Your content item knows it has 'picked' another content item, perhaps to display a shared banner across different pages, but that 'banner' content item doesn't know where it has been picked! | ||
With a Content, Member or Media picker the relationship only works as a 1-way street. The content item knows it has 'picked' another content item but that other content item does not know where it has been picked. | ||
sofietoft marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
Umbraco Relations are 2-way, when you create a relation between two different types of entities, you can alway find one entity from the other and vice versa. eg you could list out in the backoffice all the pages that a content banner had been picked on. | ||
Umbraco Relations works as a 2-way street. When creating a relation between two different types of entities, it will be possible to find one entity from the other and vice versa. As an example this provides the option to list out all the pages that a content banner had been picked on. | ||
|
||
## Relation Types | ||
|
||
To create and use Relations in your Umbraco Website, you need to define a 'Relation Type' to specify what the two types of entities will be relatable and to give the Relation Type an alias. So, you can test if two items are related for a particular 'relation type'. Two items might be related under multiple different Relation Types, and you might be only interested in your 'Related Language Page' Relation Type. | ||
To create and use Relations in your Umbraco Website, you need to define a 'Relation Type'. The Relation Type will specify what two types of entities will be relatable. Two items might be related under multiple different Relation Types, and you might be only interested in your 'Related Language Page' Relation Type. | ||
|
||
|
||
### Create a Relation Type | ||
|
||
Navigate to the **Settings** section in the Umbraco backoffice and you'll find **Relations** in the Advanced menu. | ||
|
||
 | ||
|
||
If you click on Relations in the tree, you can see that Umbraco 'ships' with some default Relation Types. These are used by the Umbraco backoffice to help deliver some key backoffice functionality: | ||
|
||
 | ||
|
||
For example, there is a Relation Type that tracks when Media is picked in Content to be able to provide the functionality of warning an editor if they try to delete a Media Item that it is 'in use'. There is a Relation Type, to help 'restore' deleted content back to the place it was deleted from in the Recycle Bin. | ||
|
||
 | ||
|
||
To create your new Relation Type, follow these steps: | ||
|
||
1. Go to the **Relations** folder. | ||
2. Provide a **Name** for the Relation Type. This will generate it's alias. | ||
3. Choose the **Direction** of the relationship to get the benefits of relations. | ||
4. Define the type of one object in the relation called **Parent** that defines which column in the database this value is stored in. | ||
|
||
For a bidirectional relationship, it doesn't matter which type of entity is defined as the Parent or the Child. If there is 'one thing' that will be related to lots of 'other things', then choose that thing as the Parent. | ||
5. Choose the different types for each entity (**Parent** and **child**) from the drop-down list. | ||
|
||
Currently the available types are: Document(Content), Media, Member, Document Type, Media Type, Member Type, Member Group, Data Type, Root, and Recycle Bin | ||
|
||
Example: For relating Members to their uploaded Images, we might create a 'Member Images' relation | ||
|
||
 | ||
6. Select **Is Dependency** as **Yes** if you wish this Relation Type to be used in Umbraco's 'tracking' functionality; that warns editors when trying to delete entities if they are 'used' in a Relation Type marked as 'Is Dependency' | ||
7. Click **Create** and you'll see your new Relation Type created in the Relation Types folder. You can see the 'Alias' that you'll need to make note of when working with Relations. | ||
## Viewing Relations | ||
|
||
 | ||
It is possible to view the existing Relation Types from the Umbraco backoffice. | ||
sofietoft marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
## Viewing Relations | ||
1. Access the Umbraco Backoffice. | ||
2. Navigate to the **Settings** section. | ||
3. Locate the **Advanced** group in the sidebar. | ||
4. Select **Relations**. | ||
|
||
To view one of the existing Relation Types, go to the **Relations** tab. It displays a long list of all the objects that have been related for this specific Relation Type. | ||
 | ||
|
||
 | ||
On the dashboard all defined relations will be listed. Select a Relation to view a list of all the objects that have been related for that specific Relation Type. | ||
|
||
## Creating Relations | ||
|
||
|
@@ -82,7 +55,7 @@ You can create Relations using the RelationService API via code. | |
|
||
You might want to create a 'Relation' between two objects either as: | ||
|
||
* A response to a backoffice event. For example, a content item being published that has picked several other content items. Storing a relationship between these items would make querying between them easier. Perhaps show all the pages on which a particular 'banner' has been picked. | ||
* A response to a backoffice event. For example, a content item being published that has picked other content items. Storing a relationship between these items would make querying between them easier. Perhaps show all the pages on which a particular 'banner' has been picked. | ||
* A logged-in member on the front end of an Umbraco website might have the facility to upload images. In response, the implementation could store the photos programmatically in the Media Section and at the same time, create a Relation to record the relationship between the member and their uploaded pictures. On an image gallery page, it would be possible to display all the gallery images for the current logged-in Member using the relations. | ||
|
||
### Community Packages | ||
|
Uh oh!
There was an error while loading. Please reload this page.