This is a follow up to a question I asked yesterday which I didn’t formulate very well (https://www.cuba-platform.com/discuss/t/button-in-a-fieldgroup).
The real issue is that cuba-platform currently doesn’t seem to support one-to-one compositions, embedded collections or collection datatype elements and I’m trying to find a workaround.
I have an entity called ContactInfo. This contains a list of addresses, a list of emails, and a list of phone numbers. Address, email and phone number are their own entities because I don’t seem to be able to use collections of a built-in datatype like String.
Several other entities should be able to have a ContactInfo attribute. Each ContactInfo uniquely belongs to an entity. Each entity should only have one ContactInfo since ContactInfo represents potentially multiple addresses, emails etc. If the owning entity gets deleted, the ContactInfo should get deleted as well.
Here’s the problem. When the user gets to an edit screen for an entity that owns ContactInfo, I would like to avoid going to a table of ContactInfo to create the ContactInfo if it already exists or going to a table of ContactInfo to select the single existing ContactInfo to edit.
So I would like to go from a PickerField directly to either creating the ContactInfo entity and going to the edit screen to fill it in, or going directly to the edit screen with the existing single ContactInfo entity.
I haven’t been able to figure out how to do this right. I’m not sure where to create the ContactInfo entity for the owning entity so that it gets picked up by the edit screen of the PickerField OpenAction. I tried instantiating in the postInit method with metadata.create and setting the ContactInfo of the new owning entity. I also played around extensively with views and created a contactInfo-view with all the properties and set the view of the ContactInfo property in the owning entity view to contactInfo-view. I keep getting “Access Denied”.
I run into issues, even when I use the unmodified PickerField and go to the browse screen and then create. When I get back to the owning entity screen, it says the ContactInfo is detached, even after it is persisted and displayed in the owning entity table which has the view where the contact info property points to the contact-info view.
Any guidance would be appreciated.
Once I can get this to work, I am OK using PickerField for now. However, PickerField is the wrong field for this sort of relationship, hence my previous question about showing a button in a field group or some more appropriate field.