Skip to content

_softDeletedAt filter do not spread for nested records #8

@SvaRgoS

Description

@SvaRgoS

Bug report

Required System information

  • Node.js version:
  • NPM version:
  • Strapi version:
  • Database:
  • Operating system:
  • Is your project Javascript or Typescript:

Describe the bug

I run the following query


query Suppliers($filters: SupplierFiltersInput, $certificationsFilters2: CertificationFiltersInput) {
  suppliers(filters: $filters) {
    data {
      id
      attributes {
        companyName
        recipient_organization {
          data {
            id
            attributes {
              name
              certifications(filters: $certificationsFilters2) {
                data {
                  id
                }
              }
            }
          }
        }
      }
    }
  }
}

some of the Suppliers have a recipient_organization that have a few deleted certifications

And they appear in the results. Unfortunately.

I guess because


const sdWrapParams = async (defaultService: any, opts: any, ctx: { uid: string, action: string }) => {
  const { uid, action } = ctx;
  const wrappedParams = await defaultService.wrapParams(opts, ctx);

  if (!plugin.supportsContentType(uid)) {
    return wrappedParams;
  }

  // Prevent users to set values for _softDeletedAt, _softDeletedById, and _softDeletedByType
  if (wrappedParams.data) {
    delete wrappedParams.data._softDeletedAt;
    delete wrappedParams.data._softDeletedById;
    delete wrappedParams.data._softDeletedByType;
  }

  return {
    ...wrappedParams,
    filters: {
      $and: [
        {
          ...wrappedParams.filters
        },
        {
          _softDeletedAt: {
            $null: true
          },
        },
      ],
    },
  };
}

the following filter

     _softDeletedAt: {
            $null: true
          },
          

apply only for top level entity.

Steps to reproduce the behavior

  1. Create two or more entities
  2. add relations between they
  3. add records to both of the table
  4. remove some of nested records
  5. Make request with related nested records.

You will see deleted records in the result

Expected behavior

I think would be good to get only non-deleted records.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions