Skip to content

[FEATURE] - dependsOn doesn't fetch relation data - requires relation in display array #664

@experimatt

Description

@experimatt

Summary

When using a virtual field with dependsOn referencing a relation, the relation data is not fetched unless the relation is also explicitly included in the display array.

Basic Example

// ❌ This doesn't work - employer data is not fetched
display: [
  {
    key: "employerName",
    label: "Employer Name",
    dependsOn: ["employer"],
    formatter: ({ row }) => {
      const emp = row?.employer;
      return `${emp?.user?.firstName ?? ""} ${emp?.user?.lastName ?? ""}`.trim();
    },
    type: "scalar"
  }
]

// ✅ This works - but requires showing the raw relation column
display: [
  "employer",  // Must include this for the virtual field to work
  {
    key: "employerName",
    label: "Employer Name",
    dependsOn: ["employer"],
    formatter: ({ row }) => {
      const emp = row?.employer;
      return `${emp?.user?.firstName ?? ""} ${emp?.user?.lastName ?? ""}`.trim();
    },
    type: "scalar"
  }
]

Expected behavior:

  • dependsOn: ["employer"] should trigger fetching the employer relation (and ideally its nested relations like employer.user), allowing virtual fields to replace relation columns entirely.

Current behavior:

  • dependsOn only declares a dependency but doesn't affect the Prisma query. The relation must be separately included in display, which defeats the purpose of creating a custom virtual field to replace it.

Additional context:

  • Supporting nested relation depth (e.g., dependsOn: ["employer.user"]) would also be valuable for formatting deeply nested data.
  • This is similar to, but not the same as, this max depth for actions issue: feat: add depth selection for actions #470

Drawbacks

No response

Unresolved questions

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions