-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Closed
Labels
issue: discussionA general discussion issueA general discussion issue
Milestone
Description
Bug report
Describe the bug
Populate is not respecting given fields in params and instead populating all fields during find query. During update query relation fields are not returned at all and there is no means to populate them.
Steps to reproduce the behavior
- Change any model relation to
autoPopulate: false - Execute find query and set populate fields to only return a specific set of fields. IE:
["users", "users.id"], have also tried simply:["users.id"] - Observe that all fields within the relation are returned and not only the id field
- Update a relation on the same model
- Observe relation is not returned when logging the updated model and the update does not actually update anything.
Expected behavior
When finding, only the provided fields in the populate params should be provided, not the entire object.
When updating, I should either be able to populate the relation I'm updating or it should return the relation I've just updated automatically.
Code snippets
Problem with find query:
const article = await strapi.query("article").findOne({ id }, ["users", "users.id"]);
console.log(article) returns:
{
users: [{
id: 1,
name: John,
email: john@test.com,
...
}]
}
Problem with update query:
const updatedArticle = await strapi.query("article").update({ id }, { users: updatedUsers });
console.log(updatedArticle.users) // returns null and also update did not actually happen
Something to note: If I change autoPopulate back to true in the models settings then updates work fine again. Not sure if I'm doing something wrong here or if this is actually a bug.
System
- Node.js version: 12.18.3
- NPM version: 6.14.6
- Strapi version: 3.4.4 & 3.5.4
- Database: mySQL
- Operating system: macOS Big Sur 11.2.2
Metadata
Metadata
Assignees
Labels
issue: discussionA general discussion issueA general discussion issue