Copied to clipboard

Flag this post as spam?

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


  • Saba Tandashvili 29 posts 181 karma points
    Nov 27, 2018 @ 06:35
    Saba Tandashvili
    0

    How to join tables in Umbraco ?

    Hi, i have simple categories and items structure. I made custom Data Type with Content Picker and administrator chooses category when he/she adds item. The problem is that i can not access category title. int itemCategoryId = allOffer.GetPropertyValue<int>("itemCategory"); Returns only category id. I can not access categoryTitle.

    As i see there is not any Include() method in umbraco which lets me to join tables, what else can i do besides of selecting entire category data from categories table by itemCategoryId.

  • Nik 1612 posts 7258 karma points MVP 7x c-trib
    Nov 28, 2018 @ 09:53
    Nik
    0

    Hi Saba,

    Can you expand a bit more on what you mean? When you say you've made a custom Data Type with Content Picker do you mean you've made a "Data Type" in the developer section that is using the Content Picker property editor?

    Working on the assumption that the above is true, and that you are now trying to access the selected category in your Razor template then you need to do the following:

    var myCategory = Umbraco.TypedContent(itemCategoryId);

    This should return your category but you will need to check for null just incase the category gets deleted :-)

    If you are using a version of Umbraco with PropertyValueConverters enabled you should be able to do the following:

    var myCategory = allOffer.GetPropertyValue<IPublishedContent>("itemCategory");

    Does that help?

    Thanks

    Nik

  • Saba Tandashvili 29 posts 181 karma points
    Dec 06, 2018 @ 16:08
    Saba Tandashvili
    0

    Hi Nik,

    Yes i have made Data Type in developers section which is using Content Picker property editor.

    I made almost same, because allOffers.GetPropertyValue is returning picked property's Id. I just hoped it to return whole object instead of only Id. So i had to access Category titles with code below :

                        int offersItemCategoryId = allOffer.GetPropertyValue<int>("offersItemCategory");
                        if (offersItemCategoryId != 0)
                        {
                            IPublishedContent offersItemCategoryObject = Umbraco.Content(offersItemCategoryId);
                            if(offersItemCategoryObject!= null)
                            {
                                offersItemCategoryTitle = offersItemCategoryObject.GetVortoValue<string>("offersCategoryTitle");
                            }
                        }
    

    I just hoped there was something like lazy loading in Umbraco.

Please Sign in or register to post replies

Write your reply to:

Draft