Skip to content

Setting autoPopulate to false on relations does not return ids. #4630

@loongmxbt

Description

@loongmxbt

Describe the bug
I need to add autoPopulate: false to relational fields (one-to-many), and later get the data.
E.g. Project has many Reports, when I add "autoPopulate": false to reports, then the whole reports field won't return. I hope to know the ids for further use.

"reports": {
      "collection": "report",
      "via": "project",
      "autoPopulate": false
    },

In N-1 relation, if set autoPopulate: false, it will return the id, e.g. project: 1.
This problem occurs when the field is 1-N and N-N relations. The field won't return.

Steps to reproduce the behavior

  1. Go to a one-to-many relational fields, e.g. Project has many reports
  2. Add autoPopulation: false to reports field
  3. GET /projects/1
  4. The report field doesn't return.

Expected behavior
I think it should behave the same, return reports: [1, 2, 3] or reports: [{id: 1}, {id: 2}, {id: 3}]

Screenshots
If applicable, add screenshots to help explain your problem.

Code snippets

{
  "connection": "default",
  "collectionName": "projects",
  "info": {
    "name": "project",
    "description": ""
  },
  "options": {
    "increments": true,
    "timestamps": [
      "created_at",
      "updated_at"
    ],
    "comment": ""
  },
  "attributes": {
    "name": {
      "unique": true,
      "required": true,
      "type": "string"
    },
    "reports": {
      "collection": "report",
      "via": "project"
    },
    "comments": {
      "collection": "comment",
      "via": "project"
    }
  }
}

System

  • Node.js version: 10.16.1
  • NPM version: 6.9.0
  • Strapi version: 3.0.0-beta.17.6
  • Database: SQLite
  • Operating system: Windows

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue: bugIssue reporting a bugseverity: mediumIf it breaks the basic use of the product but can be worked aroundsource: core:strapiSource is core/strapi packagestatus: confirmedConfirmed by a Strapi Team member or multiple community members

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions