Copied to clipboard

Flag this post as spam?

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


  • jake williamson 145 posts 626 karma points
    Aug 07, 2019 @ 05:18
    jake williamson
    0

    how to use a modelsbuilder base class with nested content in v8?

    hey out there,

    we're building a new site in v8 that uses nested content and the modelsbuilder. nice.

    in v7 projects we had a base class that all our generated models build up from e.g.

    [assembly: ModelsBaseClass(typeof(BaseModel))]
    namespace OurSite.Core.Models
    {
        public class BaseModel : PublishedContentModel
        {
            public BaseModel(IPublishedContent content) : base(content)
            {
            }
    
            public string PageTitle => this.HasValue("title") ? this.GetPropertyValue<string>("title") : Name;
        }
    }
    

    so we tried to drop this into our shiney new v8 project and everything was running sweet right up until the moment we added a nested content item...

    turns out the models generator creates the model as PublishedElementModel e.g.

    public partial class ImageCarouselItem : PublishedElementModel
    

    so we build our models and not surprisingly get the following error:

    enter image description here

    is there a way we can tell the modelsbuilder or umbraco to ignore doctypes that are elements?

    any suggestions would be grand ;)

    cheers,

    jake

  • Peter Gregory 404 posts 1562 karma points MVP 2x admin c-trib
    Aug 08, 2019 @ 00:35
    Peter Gregory
    0

    Has anyone done this? It is super important for v8 and models builder that this works. There doesn't seem to be any documentation anywhere.

  • Peter Gregory 404 posts 1562 karma points MVP 2x admin c-trib
    Aug 08, 2019 @ 00:52
    Peter Gregory
    1

    Currently still an issue in Models Builder. This really needs to be sorted ASAP.

    https://github.com/zpqrtbnk/Zbu.ModelsBuilder/issues/205

  • jake williamson 145 posts 626 karma points
    Aug 08, 2019 @ 08:19
    jake williamson
    1

    just spent some time looking at this with peter and a pull request is in ;)

    https://github.com/zpqrtbnk/Zbu.ModelsBuilder/pull/211

    this pr solves the base class issue for nested content items, it'd be good to look at the 'ElementModelsBaseClass' idea mentioned in https://github.com/zpqrtbnk/Zbu.ModelsBuilder/issues/205

    nice.

  • jake williamson 145 posts 626 karma points
    Aug 08, 2019 @ 08:42
    jake williamson
    1

    boom - part two knocked out too ;)

    https://github.com/zpqrtbnk/Zbu.ModelsBuilder/issues/205

    [assembly: ElementModelsBaseClass(typeof(ElementBaseModel))]
    

    is a go. even nicer.

  • Nik 1111 posts 4634 karma points MVP 2x c-trib
    Aug 08, 2019 @ 08:50
    Nik
    0

    I have nothing to contribute here other than nice work to you both! I wouldn't have known where to start with it, but good to hear there are PR's to get it fixed now :-D

Please Sign in or register to post replies

Write your reply to:

Draft