Practically if you have a bidirectionnal relationship and if the other way around is simpler you can update the followed and not the follower. If it’s not the case then… good question.
import {Event} from "@strapi/database/dist/lifecycles";
export default {
/**
* An asynchronous register function that runs before
* your application is initialized.
*
* This gives you an opportunity to extend code.
*/
register(/*{ strapi }*/) {},
/**
* An asynchronous bootstrap function that runs before
* your application gets started.
*
* This gives you an opportunity to set up your data model,
* run jobs, or perform some special logic.
*/
bootstrap(/*{ strapi }*/) {
strapi.db.lifecycles.subscribe({
models: ['plugin::users-permissions.user'],
// your lifecycle hooks
async beforeUpdate(event: Event) {
const user = await strapi.query('plugin::users-permissions.user').findOne({
where: event.params.where,
populate: {
follows: {
select: ['id']
}
}
})
if (user) {
event.params.data.follows = [...user.follows, ...event.params.data.follows]
}
}
})
},
};
So you just need to use that query variables : { "updateUsersPermissionsUserId": 1, "data": { "follows": [4] } }
And you have the previous follows plus the id 4 for user 1