umbraco / Umbraco-CMS

Umbraco is a free and open source .NET content management system helping you deliver delightful digital experiences.
https://umbraco.com
Other
4.49k stars 2.69k forks source link

Cannot generate model for type X because it is an element type, but its parent type Y is not #12251

Open Nikkelmann opened 2 years ago

Nikkelmann commented 2 years ago

Which exact Umbraco version are you using? For example: 9.0.1 - don't just write v9

9.4.3

Bug summary

Nesting an Element type in a Document Type (no template) causes the model builder to fail.

It gives the following message:

Failed to build models.
Cannot generate model for type 'frequentlyAskedQuestion' because it is an element type, but its parent type 'frequentlyAskedQuestionFolder' is not.

at Umbraco.Cms.Infrastructure.ModelsBuilder.Building.Builder.Prepare()
at Umbraco.Cms.Infrastructure.ModelsBuilder.Building.Builder..ctor(ModelsBuilderSettings config, IList`1 typeModels)
at Umbraco.Cms.Infrastructure.ModelsBuilder.Building.ModelsGenerator.GenerateModels()
at Umbraco.Cms.Web.BackOffice.ModelsBuilder.ModelsBuilderDashboardController.BuildModels()

It also does not allow me to pick the element type as a child note type when it is nested: image

Specifics

No response

Steps to reproduce

image

1

Create a document type without a template. image

2

Create a document type without a template under the first document type. Also note, list view is enabled for this document type. image

3

Create an element type under the second document type. image

Expected result / actual result

Either the backoffice should stop me from creating element types under document types or the model builder should generate the model as any normal type (regardless of nesting).

bielu commented 2 years ago

@Nikkelmann I think I have little different point of view on it, it should not allow you to create children with different boolean value for element type than parent, as if you look on class inheritance, as Elements and Content inherits from different base classes/interfaces and they can't have 2 base classes: https://github.com/umbraco/Umbraco-CMS/blob/5bfab13dc5a268714aad2426a2b68ab5561a6407/src/Umbraco.Core/PublishedCache/PublishedElement.cs#L17 and https://github.com/umbraco/Umbraco-CMS/blob/5bfab13dc5a268714aad2426a2b68ab5561a6407/src/Umbraco.Core/Models/PublishedContent/PublishedContentBase.cs#L14 So yeah not really case which should be supported as c# doesnt support multiple inheritance of classes: https://stackoverflow.com/questions/11134832/inherit-from-two-classes-in-c-sharp :)

nikolajlauridsen commented 1 year ago

Hey @Nikkelmann, sorry for the late reply, but I just got around to having a look at this.

I must say that I agree with @bielu, as they said when you create a child document type, you'll inherit from the parent (the document type), this becomes problematic because the child (the element) type, isn't actually a document type, and therefore shouldn't be able to inherit from a document type.

Now I do agree that it would be nice if the option for creating an element type wasn't shown when you right-click a document type, so I'll leave this as up for grabs with the proposed solution being to remove the element type entry when right-clicking a document.

Of course you could still go into the settings of the document type and convert it to an element type, which is fine IMO.

github-actions[bot] commented 1 year ago

Hi @Nikkelmann,

We're writing to let you know that we would love some help with this issue. We feel that this issue is ideal to flag for a community member to work on it. Once flagged here, folk looking for issues to work on will know to look at yours. Of course, please feel free work on this yourself ;-). If there are any changes to this status, we'll be sure to let you know.

For more information about issues and states, have a look at this blog post.

Thanks muchly, from your friendly Umbraco GitHub bot :-)