umbraco / Umbraco.UIBuilder.Issues

Back office UI builder for Umbraco
3 stars 2 forks source link

Support different foreign key types in context app collections, other than UDI #68

Closed philipdanielhayton closed 10 months ago

philipdanielhayton commented 10 months ago

It's quite common for custom data to be associated with umbraco entities via their id (int) or key (Guid).

However in UI Builder, when adding a collection to the context app, it seems to assume that the foreign key is a UDI string, and having it as anything else breaks the app. It doesn't show related items in the list view, and saving items throws an error.

Is there anyway to match the foreign key field to something other than the UDI? For example the node ID or key?

philipdanielhayton commented 10 months ago

Is it maybe possible to add a ValueMapper to the foreign key, like we do with editor fields?

I am able to support non-foreign key fields using this method. For example I have a Member Picker field that converts between Guid and UDI as needed.

mattbrailsford commented 10 months ago

Good question.

Just looking now and I think in most places we do attempt to convert the FK property passed in into the DB type, and this should use TypeConverters to do this. However it doesn't look like we do that when we call NewEntity which I think should be an easy enough thing for us to do.

If this is in place, I think you should be able to register a global type converter that knows how to convert a UDI to a GUID and I think it should work. Let me make a fix for the NewEntity method and I'll push a nightly for you to try. In the meantime, if you want to write a type converter I think that should maybe start working for the list view, and when I push this update, it should resolve the error on creating a new entry.

philipdanielhayton commented 10 months ago

Nice one, cheers Matt.

mattbrailsford commented 10 months ago

Ok should be a preview 12.0.1--preview.6 and 10.0.1--preview.7 on here now https://docs.umbraco.com/umbraco-cms/fundamentals/setup/install/installing-nightly-builds

mattbrailsford commented 10 months ago

Resolved in 10.0.1 and 12.0.1