Skip to content

Can't use where filter with relationship 4 levels deep (or more) #12721

Closed
@ryami333

Description

@ryami333

Describe the Bug

Imagine a taxonomy where 5 or more collections are related to each other, like this:

Company -> Team -> Employee -> Project -> Task

Now imagine that you might want to query for all of the tasks that are held by one team. You could (and can) do this with Payload, like this:

payload.find({
  collection: "tasks",
  where: {
    "project.employee.team": {
      equals: myTeamId,
    }
  }
});

This works correctly, but if you go one-level deeper, and try to (for example) get all of the tasks held by the entire company, you encounter a bug. This would return an empty set of docs:

payload.find({
  collection: "tasks",
  where: {
    "project.employee.team.company": {
      equals: myCompanyId,
    }
  }
});

Link to the code that reproduces this issue

https://github.com/ryami333/payload-nested-where-repro/tree/main/test/_community

Reproduction Steps

  1. Create at least 5 collections, each associated to the next by a "relationship" field (Eg. Companies, Teams, Employees, Projects, Tasks)
  2. Populate each collection with docs, using the relationship fields to "nest" the data like this:
Apple/
├── …
└── Engineering/
    ├── …
    └── Mitch/
        ├── …
        └── Data Lake Migration/
            ├── …
            ├── Design Schema Migration
            ├── Implement Data Transfer
            ├── Validate Data Integrity
            └── Decommission Old System
  1. Try to query across 4 (or more) relationship boundaries like in my example above (eg. "get all tasks in my company").
  2. You'll receive an empty array of docs.

Which area(s) are affected? (Select all that apply)

Not sure

Environment Info

See reproduction.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions