Skip to content

strapi.db.query().findMany() with select + relation filter returns only 1 row #25395

@HIJOdelIDANII

Description

@HIJOdelIDANII

Bug report

Describe the bug

When using strapi.db.query().findMany() with a top-level select parameter combined with a relation filter in where, the query returns only 1 row instead of all matching rows.

Removing the select parameter returns the correct number of rows. Using select without a relation filter also works correctly.

Strapi Version

5.33.0

Database

PostgreSQL

Steps to reproduce

Given a transaction content type with a manyToOne relation to advertiser:

// Returns 1 row (WRONG - should return 8)
const results = await strapi.db.query("api::transaction.transaction").findMany({
  where: {
    advertiser: { id: 6 },
    transaction_status: "SUCCESSFUL",
    type: "PACK_PURCHASE",
  },
  select: ["price"],
});

// Returns 8 rows (CORRECT)
const results = await strapi.db.query("api::transaction.transaction").findMany({
  where: {
    advertiser: { id: 6 },
    transaction_status: "SUCCESSFUL",
    type: "PACK_PURCHASE",
  },
  // no select
});

Controlled test results

We tested 4 query variations on the same data (8 matching rows in DB):

Query Result Expected
No select, with relation filter 8 rows 8 ✅
select: ["price"], with relation filter 1 row 8 ❌
select: ["price", "impressions"], with relation filter 1 row 8 ❌
select: ["price"], no relation filter 9 rows (all advertisers) 9 ✅

Key findings

  • The bug only occurs when select is combined with a relation filter in where
  • The number of fields in select doesn't matter (1 field or 2 fields — same result)
  • select inside populate (nested) is NOT affected — only the top-level select
  • Without select, the relation filter works correctly
  • Without the relation filter, select works correctly

Expected behavior

findMany() should return all matching rows regardless of whether select is used.

Workaround

Remove the top-level select parameter from findMany() calls that also use relation filters in where. The query will fetch all fields instead of specific ones, but will return the correct number of rows.

Metadata

Metadata

Assignees

No one assigned

    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