i have a Class “Department” with a relation “users” and an attribute userCount".
I want to set the userCount according to the count of the relation “users”. In beforeSave the changes to the relation aren’t applied and in the afterSave i will get a endless loop because I am saving the same object again.
hmm maybe something like that. afterSave trigger should trigger only once when object is saved. countUsers should be an object but .count() returning number, i don’t know how your schema looks like but maybe this will give you any clue.
I’m sorry, i didnt describe my problem very well… There is no relation or Class userCount.
I have one Class “Department” with a relation called “users” and an attribute “userCount”. And i want to sync the count of the relation to this field. So I don’t have to fetch the relation to know the count of the users in the frontend.