trim icon indicating copy to clipboard operation
trim copied to clipboard

There is no way to specifiy includes for included admin

Open X-Coder264 opened this issue 4 years ago • 0 comments

export default {

    resourceName: 'orders',

    includedRelationships: {
        index: ['client', 'school'],
        edit: ['client', 'school', 'orderPackageHistory', 'orderPackageHistory.package', 'orderPackages', 'orderPackages.package']
    },

    setupEdit({edit, method}) {

        this.addToIndexControl().addSaveControl();

        edit.addField('IncludedAdminFormElement', {
            label: 'Order packages',
            name: 'orderPackages',
            layoutReference: 'mainRegion',
            setupEdit: ({editIncluded, method, resourceModel}) => {

                editIncluded.addField('ExternalAdminFormElement', {
                    label: 'Package',
                    name: 'package',
                    mapCaptionTo: 'name',
                    relation: {type: 'hasOne', resourceName: 'packages'},
                    readOnly: method === 'edit'
                });
            },
            relation: {type: 'hasMany', resourceName: 'orderPackages', reverseRelationName: 'order'}
        });
        }
    }
};

When creating an order in my case which consists of order packages the package name is not populated (because the POST create request for the order package does not add the package include). Refreshing the page populates that data (because of the edit resource includes which are specified at the top).

Ideally, the included admin would read the already specified includes at the top and apply only the includes that are related to the included admin resource for the POST and PATCH that it does, e.g.

POST /api/v1/orderPackages?include=package instead of POST /api/v1/orderPackages

X-Coder264 avatar Apr 21 '21 20:04 X-Coder264