question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom populate options per entity

See original GitHub issue

Related to: https://github.com/meilisearch/strapi-plugin-meilisearch/issues/376#issuecomment-1123932008

Description It’d be very useful to have custom populate options per content/entity type so that we have more control over what data gets indexed and we have access to it in the transform functions.

I imagine a config like this would be fine

ENTITY: {
  settings: {
    ...
    populate: {
      field: '*'
    },
    ...

Basic example Sometimes you have more complex data structures with deep nested components and references and you need access to the underlying information or at the very least to have it available in the index.

For example, if you have a single use component field with a component referencing another content type, such as a date period component referencing a timezone, the generic populate: ‘*’ doesn’t currently cover the deep nesting required.

This is the patch we’ve used to add our custom populate for one content type, ideally you can override the populate: '*' instead.

diff --git a/node_modules/strapi-plugin-meilisearch/server/services/content-types/content-types.js b/node_modules/strapi-plugin-meilisearch/server/services/content-types/content-types.js
index 1e5f6a2..5adf3dd 100644
--- a/node_modules/strapi-plugin-meilisearch/server/services/content-types/content-types.js
+++ b/node_modules/strapi-plugin-meilisearch/server/services/content-types/content-types.js
@@ -142,7 +142,27 @@ module.exports = ({ strapi }) => ({
     limit = 500,
     filters = {},
     sort = {},
-    populate = '*',
+    populate = {
+      programme: {
+        populate: {
+          programme_logo: '*'
+        }
+      },
+      event_type: '*',
+      featured_image: '*',
+      topics: '*',
+      languages: '*',
+      location: {
+        populate: {
+          country: '*',
+        }
+      },
+      dates: {
+        populate: {
+          timezone: '*',
+        }
+      },
+    },
     publicationState,
   }) {
     const contentTypeUid = this.getContentTypeUid({ contentType })

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
paulpopuscommented, May 25, 2022

In the future I’d still like to explore an populate override in the cases where people have prewritten populate objects that they want to re-use across services/plugins.

Could you explain how it would work and how it is different?

Wait…I think I’m just confused 😅

Ignore me, I’ll open a separate issue with the explainer if it’s still a problem for us next week.

Thanks again for your fast work on these plugin issues!

0reactions
bidoubiwacommented, May 25, 2022

In the future I’d still like to explore an populate override in the cases where people have prewritten populate objects that they want to re-use across services/plugins.

Could you explain how it would work and how it is different?

Read more comments on GitHub >

github_iconTop Results From Across the Web

auto populate custom entity using java script without...
i have created two custom entity named cts_agent,cts_cases, now i need to auto populate all the fields of cts_cases which are read only...
Read more >
How to populate nested entity in Mongoose? - Stack Overflow
I recommend you to add reference to workspace model at the user schema declaration: workspace: { type: mongoose.Schema.
Read more >
Solved: Auto populate the Primary Name column with the com...
Solved: Hello, I have a simple lookup table with four columns - Project Manager 1) Manager Name (Primary name) 2) First Name 3)...
Read more >
NetSuite Tips - Using The Advanced Features Of Custom Fields
NetSuite tips from NoBlue. This guide is all about using the advanced features of custom fields so that you can make them work...
Read more >
Relationship Loading Strategies - MikroORM
By default, populated relationships are loaded via the select-in strategy. This strategy issues one additional SELECT statement per relation being loaded.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found