Copied to clipboard

Flag this post as spam?

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


  • Rickard Liljeberg 23 posts 114 karma points
    Dec 10, 2015 @ 14:13
    Rickard Liljeberg
    0

    Linking document types together

    I am very new to developing with Umbraco (but used .net mvc for years).

    In this, my first project, I need to be able to create regions and categories where each region and category should contain description and possibly an image and be displayed as pages of their own.

    Now this is easy enough, I create the document types, templates and go ahead and create some pages/nodes.

    But here comes the trick... I now also need to create companies but each company can be active in one or more regions and fall within one or more categories. So if I create a Company document type, how do i then make it so that I can link to the regions/categories that this company is active in?

    Would that be a kind of custom coupling or how do I accomplish this?

    I also want to be able to on the page for a region list which companies (and link to) are active in that region.

    Any hints would be appreciated!

  • Ian 178 posts 752 karma points
    Dec 10, 2015 @ 21:30
    Ian
    0

    I have always used the nuPickers Package for umbraco to do this together with Umbraco's Relations feature. Once installed you can then create a new datatype which uses one of the available nuPickers Types and attach a property to one of your document types using that datatype. In my case I created a nupicker datatype which I named 'sector picker' this was a 'nuPickers: Xml PrefetchList' which can be configured to use umbraco's XPath queries to get content. My XPath query selected all children of a 'sector repository' document type i'd created.

    The editor just gets to see a list of sectors they can select from when editing a page, but because the datatype is configured to place those selections into a sector 'Relation Type' i'd created I was able to create a view which got a list of related items using ApplicationContext.Services.RelationService. I selected nuPickers because is seemed pretty flexible giving the option to display options as checkboxes, a drop down etc if desired. See another thread for more info here. https://our.umbraco.org/projects/backoffice-extensions/nupickers/questionssuggestions/60250-How-does-relations-work

  • Rickard Liljeberg 23 posts 114 karma points
    Dec 15, 2015 @ 19:58
    Rickard Liljeberg
    0

    I must confess I never did try your solution because what I used to seem to work fine is that i created my own data type based on a Multinode treepicker.

    Then I assigned a picker of Regions to my company, now the user can simply select all the regions the company operate in.

    The company gets the result saved as a property with the value like this "id1, id2, id3".

    So then I simply when i needed to list I split out those strings and used the id's.

    Then I did "Route hijacking" by creating a controller that will be called when my view is called. There I user a custom view model that inherit RenderModel.

    On this view model I set for instance my region and for each region which companies are in it. Thusly I don't have any ugly logic in my view and it's pretty simple.

    My only complaint about this solution is that because the id's are stored as a comma separated string I cannot do some linq like this companies.Where(x => x.regions.Any(y => y.id == loopRegion.id))

    That is basically the one thing that I am missing and that would have been perfect.

Please Sign in or register to post replies

Write your reply to:

Draft