@@ -8,17 +8,25 @@ Only relations that are actually set will be populated.
88
99``` ts
1010// Option 1: get the populate object and use where you see fit
11- const populate = await strapi .plugin (" deep-populate" ).service (" populate" ).getPopulate ({ documentId: ' xyz' , contentType: ' api::page.page' })
11+ const populate = await strapi .plugin (" deep-populate" ).service (" populate" ).get ({ documentId: ' xyz' , contentType: ' api::page.page' })
1212const document = strapi .documents (' api::page.page' ).findOne ({ documentId: ' xyz' , populate })
1313```
1414``` ts
15- // Option 2: use the wrapped `findOne` method around documentService
15+ // Option 2: use the `findOne` method that wraps around documentService.findOne
1616const { findOne } = strapi .plugin (" deep-populate" ).service (" populate" ).documents (" api::page.page" )
1717const document = await findOne ({ documentId: ' xyz' })
18+ ```
19+
20+ ``` ts
21+ // Using the wrapped FindOne provides some handy features:
1822
19- // You can also override the populate this way:
23+ // Allow you to override the populate this way:
2024const documentWithCreatedBy = findOne ({ documentId: ' xyz' , populate: [' createdBy' ]})
2125const documentWithoutSection = findOne ({ documentId: ' xyz' , populate: { section: false }})
26+
27+ // And if you supply a `*` as populate, it will return a fully populated document (i.e. non-sparse)
28+ const sparseDocument = findOne ({ documentId: ' xyz' }) // sparse, so only attributes are returned that have a value
29+ const fullDocument = findOne ({ documentId: ' xyz' , populate: ' *' }) // fully populated, so all attributes are returned
2230```
2331
2432### populateCreatorFields
0 commit comments