I have a field that needs to be automatically managed in the background. It’s fairly critical to the data integrity of my model, therefore it’s a required field.
The problem is that I don’t want to deal with setting this field in every place in the app I use the model. I had set it up to self-manage in beforeSave() but this failed because beforeSave() is never even called if validation fails, which it does if the field is missing.
I solved this by taking it out from the required in the validation rules and then taking care of setting it in beforeSave().
But I don’t like that. I would feel better about keeping it marked as required and simply having something like a “beforeValidate()” where I can check for these kinds of things and choose how to deal with them.
I couldn’t find any such method in the docs, but I feel like there’s a good chance I simply missed it. If someone knows, let me know. If no such method exists, I hope someone considers this as a decent feature request to add in.