Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
loongmxbt opened this issue Nov 30, 2019 · 12 comments
Closed

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

loongmxbt opened this issue Nov 30, 2019 · 12 comments
Labels
issue: bug Issue reporting a bug severity: medium If it breaks the basic use of the product but can be worked around source: core:strapi Source is core/strapi package status: confirmed Confirmed by a Strapi Team member or multiple community members

Comments

@loongmxbt
Copy link
Contributor

loongmxbt commented Nov 30, 2019

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.

@derrickmehaffy

This comment has been minimized.

@loongmxbt

This comment has been minimized.

@lauriejim lauriejim added severity: low If the issue only affects a very niche base of users and an easily implemented workaround can solve status: confirmed Confirmed by a Strapi Team member or multiple community members issue: bug Issue reporting a bug labels Dec 4, 2019
@lauriejim lauriejim changed the title Setting autoPopulate: false (one to many) does not return ids. Setting autoPopulate to false on One to-Many relations does not return ids. Feb 11, 2020
@lauriejim lauriejim added the source: core:strapi Source is core/strapi package label Feb 11, 2020
@jonpalmisc
Copy link

Any update or workaround on this? I'm having the same issue.

@jonpalmisc
Copy link

I'm not familiar with the Strapi code base, but I would be more than happy to try to fix this myself if you could point me in the right direction! @derrickmehaffy

@lauriejim lauriejim changed the title Setting autoPopulate to false on One to-Many relations does not return ids. Setting autoPopulate to false on relations does not return ids. Aug 11, 2020
@lauriejim lauriejim added severity: medium If it breaks the basic use of the product but can be worked around and removed severity: low If the issue only affects a very niche base of users and an easily implemented workaround can solve labels Aug 11, 2020
@balmacefa
Copy link

Any progress on this? Does anybody have a workaround?

@derrickmehaffy
Copy link
Member

@balmacefa this is something we are planning to look at in the Strapi v4 version along with the major database changes coming in Q3

@derrickmehaffy derrickmehaffy added this to the 4.0.0 milestone May 7, 2021
@alightgoesout
Copy link

My workaround was to let autopopulate as true but to replace the items by their ids using the afterFind lifecycle hook. It's not ideal since the whole item is still retrieved from the database, but the json response only contains the ids.

@derrickmehaffy
Copy link
Member

This issue has been mentioned on Strapi Community Forum. There might be relevant details there:

https://forum.strapi.io/t/rest-api-retrieve-id-only-ids-of-relations/3399/5

@dasw3
Copy link

dasw3 commented Aug 11, 2021

This issue has been mentioned on Strapi Community Forum. There might be relevant details there:

https://forum.strapi.io/t/rest-api-retrieve-id-only-ids-of-relations/3399/5

Derrick, I linked the Strapi community to this issue, there is no solution there. Now it is just circular references to the same issue in multiple areas.

@Convly
Copy link
Member

Convly commented Aug 11, 2021

This issue has been mentioned on Strapi Community Forum. There might be relevant details there:
https://forum.strapi.io/t/rest-api-retrieve-id-only-ids-of-relations/3399/5

Derrick, I linked the Strapi community to this issue, there is no solution there. Now it is just circular references to the same issue in multiple areas.

This is an automated reply when an issue is mentioned on the forum 😉

@Convly
Copy link
Member

Convly commented Aug 11, 2021

I'll also link Alex's answer posted in a duplicate of this issue:
#7361 (comment)

@derrickmehaffy derrickmehaffy removed this from the 4.0.0 milestone Nov 30, 2021
@derrickmehaffy
Copy link
Member

autopopulate doesn't exist anymore, closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: bug Issue reporting a bug severity: medium If it breaks the basic use of the product but can be worked around source: core:strapi Source is core/strapi package status: confirmed Confirmed by a Strapi Team member or multiple community members
Projects
None yet
Development

No branches or pull requests

8 participants