umbraco / Umbraco.UIBuilder.Issues

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

When creating an entity from a context app, the FK property value is set to 0, not to the related context ID #86

Closed matt-tolliday-iss closed 6 months ago

matt-tolliday-iss commented 8 months ago

Describe the bug When creating an entity from a context app, the FK property value is set to 0, not to the related context ID.

In the below example, a context app configured for the Member has a custom table called Enquiry, where the configuration uses the ID field of the Enquiry as ID property, and the MemberID field as FK identifier. When using the context app to create a new Enquiry, the value of the MemberID FK is not set to the current member being viewed, but it is set to 0. This means that the new record is available for any Member.

Steps To Reproduce Steps to reproduce the behavior:

  1. Create context app for members
  2. create new entity in context app UI
  3. check data value set for FK property ID
cfg
    .WithSection("member")
    .WithTree("member", cfg => cfg
        .AddContextApp("Enquiries", contextAppConfig => {
            contextAppConfig.AddCollection<EnquiryDto>(x => x.Id, id => id.MemberId, "Member Enquiry", "Member Enquiries", "An enquiry", "icon-help-alt", "icon-help-alt", ccfg => ccfg
            .AddFilterableProperty(p => p.Text, filterconfig => filterconfig
                .SetLabel("Text")
                .SetDescription("The content of the enquiry")
            )
            .SetNameProperty(p => p.Title)
            .SetDateCreatedProperty(p => p.CreatedOn)
            .SetDeletedProperty(p => p.IsDeleted)
            .ListView(listViewConfig => listViewConfig
                .AddField(p => p.Text)));

Expected behavior The value stored in the property marked as the FK identifier should be the ID of the context app node - in the above example, i would have expected MemberId on the Enquiries table to be populated with the Member ID.

As the value is saved as 0 (default non-nullable int) then it becomes available against every entity (member in this case)

Screenshots

image

**Environment


This item has been added to our backlog AB#37143

acoumb commented 6 months ago

Hi @matt-tolliday-iss ,

You can find a fix for this with today's release candidate version of 13.1.0.

Thank you, Adrian