Copied to clipboard

Flag this post as spam?

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


  • Anders Brohus 194 posts 475 karma points
    Jun 22, 2020 @ 13:14
    Anders Brohus
    0

    Extend Models Builder Models in v8

    Hi Our..

    I'm having an stange problem when i'm trying to extend the models that the models builder generates .. :/

    I have this field

        [ImplementPropertyType("categoryName")]
        public string CategoryName => this.Value<string>("categoryName");
    

    In an SubjectTopCategory.generated.cs file and then i want to extend it to take the node's name if this field is empty.

    So what i did was create an SubjectTopCategory.cs and it has this code in it..

    public partial class SubjectTopCategory : PublishedContentModel
        {
            [ImplementPropertyType("categoryName")]
            public string CategoryName
            { 
                get { 
                    string categoryName = this.Value<string>("categoryName");
    
                    if (string.IsNullOrWhiteSpace(categoryName))
                    {
                        categoryName = this.Name;
                    }
    
                    return categoryName; 
                } 
            }
        }
    

    But the generated model keeps generating the field ..

    It's an Umbraco Cloud project which has been setup using these ModelBuilder configs

     <add key="Umbraco.ModelsBuilder.Enable" value="true" />
        <add key="Umbraco.ModelsBuilder.ModelsMode" value="LiveAppData" />
        <add key="Umbraco.ModelsBuilder.AcceptUnsafeModelsDirectory" value="true" />
        <add key="Umbraco.ModelsBuilder.ModelsDirectory" value="~/../ProjectName.Core/Models" />
        <add key="Umbraco.ModelsBuilder.ModelsNamespace" value="ProjectName.Core.Models" />
    
  • Comment author was deleted

    Jun 22, 2020 @ 13:29

    Not 100% sure but do you need to inherit from : PublishedContentModel in your custom class?

  • Anders Brohus 194 posts 475 karma points
    Jun 22, 2020 @ 13:30
    Anders Brohus
    0

    I'm not sure either, but i have tried with it and without it .. :)

  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Jun 22, 2020 @ 13:45
    Nik
    0

    What version of Models Builder are you using Anders?

    If it's the Embeddedd version that ships with Core, I don't believe you can override the generation of properties on models as it's a cut down version. You might need to install full models builder to generate your own properties.

    Nik

  • Anders Brohus 194 posts 475 karma points
    Jun 22, 2020 @ 18:53
    Anders Brohus
    0

    It's the embedded version.. :)

    I will try and install the full models builder and return .. :)

Please Sign in or register to post replies

Write your reply to:

Draft