Search code examples
mongodbstrapi

How to unset relation in 'find'?


I have content type "Novel" and have relation with "Tag" and "Genre", I want to only show "Tag" and "Genre" in 'findOne' but not in 'find'. using m.unset in models/Novels.js only working if the data is not relation. how can I un-populate this Tag in 'find'?


Solution

  • You can deal with that by updating the find function of the Novel API.

    📚Here is the documentation to update the controller function https://strapi.io/documentation/3.0.0-beta.x/guides/controllers.html

    You will have to copy and past the find function code.

    And replace return strapi.services.product.find(ctx.query); by return strapi.services.product.find(ctx.query, []);

    We add an empty array because the second argument is here to specify data you want to populate. By passing an empty array you say to not populate data.