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

Models are not being included on delete method. #19

Merged
merged 2 commits into from
Jan 15, 2024

Conversation

ivatra
Copy link
Contributor

@ivatra ivatra commented Dec 27, 2023

Description

When you try to execute delete method with "include" param, function createDeleteParams doesn't consider it.

Query

 const res = await prisma.key.delete({
    where: {
      id: 6
    },
    include: {
      game: true,
      manager: true,
    },
  });

Actual query results

{
  id: 6,
  managerId: 3,
  gameId: 10,
  deletedAt: 2023-12-27T01:57:28.486Z
}

Expected query results

{
  id: 6,
  managerId: 3,
  gameId: 10,
  deletedAt: 2023-12-27T01:58:15.158Z,
  game: { ... },
  manager: {
    ...
  }
}

Solution

It can be fixed easily by adding ...params.args to returning params object in createDeleteParams. Or you may explicitly pass params.args.include so be sure unconsidered data won't be in params.

Environment

Prisma-soft-delete-middleware version: 1.1.2
Prisma version: 5.2.0
Node.js version: 18.12.1

Copy link
Owner

@olivierwilkinson olivierwilkinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi there,

Thanks for raising this, you are totally right that this is broken! I've made some adjustments so we only spread for a top level delete rather than a nested delete, spreading in the nested delete case was causing some test failures.

I've also added some extra test cases to be sure I didn't miss other places where you can include.

It's passing the tests now so LGTM!

I'll have a look at your other PR later on today 🙌

@olivierwilkinson olivierwilkinson merged commit 04ddd6c into olivierwilkinson:main Jan 15, 2024
2 checks passed
Copy link

🎉 This PR is included in version 1.3.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants