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

[Bug]: Can not remove a ManyToMany relation #1743

Open
ImArxus opened this issue Feb 13, 2025 · 0 comments
Open

[Bug]: Can not remove a ManyToMany relation #1743

ImArxus opened this issue Feb 13, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@ImArxus
Copy link

ImArxus commented Feb 13, 2025

Contact Details

No response

What happened?

Hello,

I want to delete a relation between two resources (ManyToMany), but I can only delete the associated record, as shown in the following picture.
Did I miss something? Do you know if I need to have an additional configuration?
Image

I tried to change the delete options in relation features configuration as follows, but here is the result:
Image

Here is my relation features configuration:

features: [
    getUploadFeature(
      service.getBackgroundImageS3PathPrefix(),
      backgroundImageKey
    ),
    getUploadFeature(service.getOverviewImageS3PathPrefix(), overviewImageKey),
    owningRelationSettingsFeature({
      componentLoader,
      licenseKey: process.env.LICENSE_KEY as string,
      relations: {
        stores: {
          type: RelationType.ManyToMany,
          junction: {
            joinKey: "offerId",
            inverseJoinKey: "storeId",
            throughResourceId: "StoreOffer"
          },
          target: {
            resourceId: "Store"
          },
          deleteOptions: {
            enableDeleteRelation: true,
            enableDeleteRelatedRecord: false
          }
        }
      }
    }),
    targetRelationSettingsFeature()
]

I also have a custom handler for delete action, maybe it can cause an issue:

actionType: "record",
    before: async (request) => {
      const recordId = request.params.recordId;
      if (recordId) {
        await service.delete(recordId);
      }
      return request;
    },
    icon: "Trash",
    after: async (
      response: ActionResponse,
      _request: ActionRequest,
      context: ActionContext
    ) => {
      const resourceName = context.resource.id();
      const message = `The ${resourceName} was successfully removed`;
      response.notice = {
        message: message,
        type: "success"
      };
      response.redirectUrl = context.h.resourceUrl({
        resourceId: resourceName
      });

      return errorHandler(response);
}

And here are the request to create the relation table:

CREATE TABLE "store_offer" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), "deletedAt" TIMESTAMP, "storeId" uuid NOT NULL, "offerId" uuid NOT NULL, CONSTRAINT "PK_d337e2be4dd1445aa51f9641ad7" PRIMARY KEY ("id"))
CREATE UNIQUE INDEX "unique_constraint_store_offer" ON "store_offer" ("offerId", "storeId") WHERE "deletedAt" IS NULL

Thanks

Bug prevalence

Always

AdminJS dependencies version

"dependencies": {
    "@adminjs/express": "^6.1.0",
    "@adminjs/relations": "^1.1.2",
    "@adminjs/typeorm": "^5.0.1",
    "@adminjs/upload": "^4.0.2",
    "adminjs": "^7.8.12"
}

What browsers do you see the problem on?

Chrome

Relevant log output

Relevant code that's giving you issues

@ImArxus ImArxus added the bug Something isn't working label Feb 13, 2025
@ImArxus ImArxus changed the title [Bug]: Can not remove a relation [Bug]: Can not remove a ManyToMany relation Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant