Operating System: Run strapi inside docker container
Database: postgres:14
Node Version: v16.11.1
Hi,
I have two separate models. Let’s say, one is Book and the other is Page. One book has one or multiple pages. When I create one new Book entity in Content Manager UI, I want to automatically create X number of Page entities and they are linked to the Book that I created. Like, after I click the default “Save” button, a book is created as usual and X pages are automatically created.
Is it possible? Which document should I look at? Thank you all very much.
Thanks @Shekhar for pointing me in the right direction!
I added a new file under api/{name}/content-types/{type-name}/lifecycles.ts
export default {
async afterCreate(event) {
const { result, params } = event;
await strapi.entityService.create(
"api::another-type.another-type",
{
data : {
Relation: [result["id"]] // This is how I link the sub-entries with the main entry.
}
});
}
}