Automatically create related content type

System Information
  • Strapi Version: 4.21.1
  • Operating System: Windows 10
  • Database: SQL Lite
  • Node Version: 20.10
  • NPM Version: 10.4
  • Yarn Version:

Dear Strapi community,

I have two collection-types, one called “Member” where each entry includes specific information on a person’s profile and another called “Fee” where each entry represents a record of yearly fees paid by each member.

The Member collection has a one-way relation to the Fee collection.

I want to know if there is a way to automatically create an entry in the Fee collection everytime I add a new entry to the “Member” collection. I know lifecycle hooks exist, but have no idea if they can be used to start requests based upon changes in other collections.

Cheers and thank you :slight_smile:
Francisco

In afterCreate of Member you generate a fee, the id of the created fee you use to update the fee-Field in the created Member entry.
Might also be possible to do that in beforeCreate of Member without the need of updating the Member entry afterwards.

Thank you, @lolafkok!

I’m quite new to Strapi and wasn’t thinking of the Entity Service API for this. I’m mostly familiarised with Rest API as a way of communicating with Strapi.

I’ll try both approaches - before and after Create. Still need to decide whether I’ll go for a one-way or one-to-one relation between collections and I can already predict some validation errors will happen.

Again, thanks and cheers,
Francisco