I'm looking at Umbraco for a project we're going to be working on - so far it's been pretty easy, I like that I've been able to achieve quite a bit via configuration, however I'm starting to get stuck.
Say I have a document type for a 'book', and I want to associate an 'author' with it. In MVC I'd usually define a model relationship. So far in Umbraco I just have a book document type. Should I also be creating an author document type, so that I can assign an author to a book from a list of previously created authors? Perhaps using the content picker type of editor?
What's the typical Umbraco way of doing something like this? I haven't found anything in the documentation here although it seems fairly fundamental, have I missed it?
Document Types are one of the building blocks of umbraco very flexible, but sometimes over used for creating models where it just isn't appropriate, say for one field. That said I think in this case a document type of of author makes sense as each author could well have a page which shows a biography , a list of their books. Sometimes relationships are made through a parent, child association i.e with a repository and its children.
In other cases the relationships feature of umbraco offers one way or bi-directional associations between objects. These do need to have content node ids on the objects being related and therefore your entities would need to be document types.
Once you have created a relation type, one picker to form these relations automatically is nuPickers. The default umbraco multinode content picker does not do this automatically, though you can use the content save events to look at the picked items on your property and form the relationships yourself using the relationservice. nuPickers can derive the options available to editors from you content structure using xpath, static options, or external code using one of their DotNet pickers.
If you think will do a reasonable amount of many to many querying from different points across the site and it doesn't create a bloated node structure i would say use relationships.
Otherwise the model relationship will be defined by the property editor you use. A picker will give you a model with a list of ids for you to gather underlying data.
Nested content will give you a list of 'virtual' content nodes taking advantage of the properties available on real content nodes. (the data for this is only stored in the property editor model)
Archetype will store a set of fieldsets in json format (again on the property model) which contain the properties you create when configuring the datatype.
I can see how to do half of what I want with document types - a content picker allows me to select previously created authors when adding a book. However, I can't see how I could display all book associated with an author by this method?
You create and edit 'relation types' in the developer section of umbraco.
You then use the relationservice to get the relations you require associated with a particular relation type.
This is the documentation for the relationservice. As you can see you can use this service to not only retrieve relations but to also create the associations from code.
As I say nuPickers saves the hassle of forming the associations leaving you to gather them in your razor templates using the most appropriate method from the relationservice.
In my case I had articles related to particular services. A bi-directional relationtype was created with document set a both and parent and child
Then when i was on an article and wanted to get other articles related by the same set of services i did this.
Document type (model?) relationships
I'm looking at Umbraco for a project we're going to be working on - so far it's been pretty easy, I like that I've been able to achieve quite a bit via configuration, however I'm starting to get stuck.
Say I have a document type for a 'book', and I want to associate an 'author' with it. In MVC I'd usually define a model relationship. So far in Umbraco I just have a book document type. Should I also be creating an author document type, so that I can assign an author to a book from a list of previously created authors? Perhaps using the content picker type of editor?
What's the typical Umbraco way of doing something like this? I haven't found anything in the documentation here although it seems fairly fundamental, have I missed it?
Thanks,
Toby
Document Types are one of the building blocks of umbraco very flexible, but sometimes over used for creating models where it just isn't appropriate, say for one field. That said I think in this case a document type of of author makes sense as each author could well have a page which shows a biography , a list of their books. Sometimes relationships are made through a parent, child association i.e with a repository and its children.
In other cases the relationships feature of umbraco offers one way or bi-directional associations between objects. These do need to have content node ids on the objects being related and therefore your entities would need to be document types.
Once you have created a relation type, one picker to form these relations automatically is nuPickers. The default umbraco multinode content picker does not do this automatically, though you can use the content save events to look at the picked items on your property and form the relationships yourself using the relationservice. nuPickers can derive the options available to editors from you content structure using xpath, static options, or external code using one of their DotNet pickers.
If you think will do a reasonable amount of many to many querying from different points across the site and it doesn't create a bloated node structure i would say use relationships.
Otherwise the model relationship will be defined by the property editor you use. A picker will give you a model with a list of ids for you to gather underlying data.
Nested content will give you a list of 'virtual' content nodes taking advantage of the properties available on real content nodes. (the data for this is only stored in the property editor model)
Archetype will store a set of fieldsets in json format (again on the property model) which contain the properties you create when configuring the datatype.
Thanks for getting back to me!
What is 'the relationships feature of umbraco', I have not seen this? If I search for 'relationship' in the docs here, nothing comes up; is it something to do with this half-empty page https://our.umbraco.org/Documentation/Reference/Management/Models/Relation?
I can see how to do half of what I want with document types - a content picker allows me to select previously created authors when adding a book. However, I can't see how I could display all book associated with an author by this method?
Toby
You create and edit 'relation types' in the developer section of umbraco.
You then use the relationservice to get the relations you require associated with a particular relation type.
This is the documentation for the relationservice. As you can see you can use this service to not only retrieve relations but to also create the associations from code.
As I say nuPickers saves the hassle of forming the associations leaving you to gather them in your razor templates using the most appropriate method from the relationservice.
In my case I had articles related to particular services. A bi-directional relationtype was created with document set a both and parent and child
Then when i was on an article and wanted to get other articles related by the same set of services i did this.
then
One of the reasons I chose relations was for their 1 to many qualities and because I also wanted to relate my entities by other criteria too.
Ok, thanks again, I will have a look.
Toby
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.