-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
Open
Description
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
selectis combined with a relation filter inwhere - The number of fields in
selectdoesn't matter (1 field or 2 fields — same result) selectinsidepopulate(nested) is NOT affected — only the top-levelselect- Without
select, the relation filter works correctly - Without the relation filter,
selectworks 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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels