Skip to content

Populate not working as expected #9970

@ashmore11

Description

@ashmore11

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

  1. Change any model relation to autoPopulate: false
  2. 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"]
  3. Observe that all fields within the relation are returned and not only the id field
  4. Update a relation on the same model
  5. 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

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions