Auto populate title field with content from other fields

Here’s what finally works the way I want it to. In my src/api/house/content-types/house/lifecycles.js:

module.exports = {
    async beforeCreate(event) {
        const { data } = event.params;
        
        const houseType = await strapi.db.query('api::house_type.house_type').findOne({
            where: { id: data.house_type }
        });

        data.title = `${data.bed} bed / ${data.bath} bath / ${houseType.name} / ${data.rent} USD a month`;
    },
    async beforeUpdate(event) {
        const { data } = event.params;

        const houseType = await strapi.db.query('api::house_type.house_type').findOne({
            where: { id: data.house_type }
        });

        data.title = `${data.bed} bed / ${data.bath} bath / ${houseType.name} / ${data.rent} USD a month`;
    }
}```
1 Like