首先,您需要一个自定义控制器功能。
在/api/person/controllers/Person.js
您可以导出自定义查找功能。您可以在此处定义要填充的字段:
module.exports = {
find: ctx => {
return strapi.query('person').find(ctx.query, ['address', 'contact']);
},
};
另一个解决方案也适用于我:
module.exports = {
find: ctx => {
return strapi.query('person').find(ctx.query, [
{ path: 'address' },
{ path: 'contact' },
]);
},
};
编辑后的示例具有更深一层的填充:
module.exports = {
find: ctx => {
return strapi.query('person').find(ctx.query, [
{
path: 'address',
populate: {
path: 'contacts',
},
},
]);
},
};
作为参考,请参阅最新的测试版文档:
https://strapi.io/documentation/3.0.0-beta.x/concepts/queries.html#api-reference