Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to delete record from admin in postgres if collection has array field type #6485

Closed
aymanson opened this issue May 24, 2024 · 2 comments · Fixed by #6735
Closed

Unable to delete record from admin in postgres if collection has array field type #6485

aymanson opened this issue May 24, 2024 · 2 comments · Fixed by #6735
Assignees

Comments

@aymanson
Copy link

aymanson commented May 24, 2024

Link to reproduction

No response

Describe the Bug

I am using the postgresdb adapter. and update the Users collection with following additional field:

        {
            name: 'roles', // required
            type: 'select', // required
            hasMany: true,
            admin: {
                isClearable: true,
                isSortable: true, // use mouse to drag and drop different values, and sort them according to your choice
            },
            options: [
                {
                    label: 'Super Admin',
                    value: 'superadmin',
                },
                {
                    label: 'Owner',
                    value: 'owner',
                },
                {
                    label: 'Admin',
                    value: 'admin',
                },
                {
                    label: 'Instructor',
                    value: 'instructor',
                }
            ],
        },
    I can save the document successfully and I notice payload create an additional table user_roles to track that. When I try to delete the record from admin. It looks like the user_roles record are not removed first nor the cascade delete is executed when delete from user. That cause the fk_constraint error in user_roles table which block the delete operation.

I noticed there are some discussion about cascade in relationship but there is no conclusion there. I want to know if there are some existing workaround for that using hook but I am not able to find such information in the documentation as well.

To Reproduce

Create a new project using the default user schema.
Modify Users.ts with additional field

   fields: [
        {
            name: 'roles', // required
            type: 'select', // required
            hasMany: true,
            admin: {
                isClearable: true,
                isSortable: true, // use mouse to drag and drop different values, and sort them according to your choice
            },
            options: [
                {
                    label: 'Super Admin',
                    value: 'superadmin',
                },
                {
                    label: 'Owner',
                    value: 'owner',
                },
                {
                    label: 'Admin',
                    value: 'admin',
                },
                {
                    label: 'Instructor',
                    value: 'instructor',
                },
                {
                    label: 'Student',
                    value: 'student',
                },
                {
                    label: 'VIP',
                    value: 'vip',
                },
            ],
        },
    ],

Create a user through the payload cms admin page.
Try delete the user through the payload cms admin page and error toast occured.

Payload Version

2.18.3

Adapters and Plugins

db-postgres

@denolfe denolfe added the status: needs-triage Possible bug which hasn't been reproduced yet label May 26, 2024
@github-actions github-actions bot removed the status: needs-triage Possible bug which hasn't been reproduced yet label Jun 10, 2024
ikenox added a commit to ikenox/payload that referenced this issue Jun 12, 2024
@ikenox
Copy link

ikenox commented Jun 12, 2024

Due to this issue, collection data that has select-hasMany field cannot be deleted on admin panel.
The API returns 500 error.

image

Minimum reproducible: ikenox@fcf1429

Copy link

github-actions bot commented Sep 7, 2024

This issue has been automatically locked.
Please open a new issue if this issue persists with any additional detail.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
4 participants