First time really cracking this open for some more “complex” validation and came up with this question.
A User object has some validation constraints on it which should act differently in insert vs. update scenarios. One simple example of using, then, the profiles feature of validation, an “add” and “update” profile can be made which can easily omit the userid for validation processing when I am in “add” mode (for example, simple checking to see if the id is 0). However, what about situations where the field validation is required for both circumstances, add or update, but the validation differs in each case? Because the validation configuration for the object requires that the key validation names match the field names, I cannot, for example, have an add_email and update_email duo of constraints because only the field name “email” exists but I want two different conditions met for validation based on whether I’m adding this person or updating them.
For now, I found a wonderful example leverage the super duper excellent qb so that if the user id is 0, I can add an additional clause to that validation UDF. I love the way it works, but I want to know if I’m always going to have to do it that way or if it is possible to configure two different constraints for the same field based on some condition. I thought about an “alias” option so that you can name the validation key what you want then identify what field it aliases to but don’t see any kind of option like that (not that this would be the right approach or a good idea)…wondering if anyone else has run into something similar and has a design pattern that could be leveraged?
Thanks for any insight.
Mike