We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How to get the name of the process: Create or Update in my custom validator?

My validator checks if there are identical time period records in the database or within those periods when i insert new data.

It fails though when i try to update existing records since i update can be within existing time period.

I'd like to use the same validator for update with small condition within that if the process is Update, skip validating.

Can i get the name of the process?



125.8k
Accepted
answer
edited Apr '16

There are 2 ways I can think of to skip validation

  1. Tie in to the beforeValidateOnCreate event, with your model. In that method, set a "bypass_time_validation" flag. In your validation method, check for the existence of that flag.
  2. In your validation method, check if the id is set. If it is, then you're updating, not saving.

However, what you want to do is probably not skip validation - because I imagine it's still possible for an existing record to conflict with some other record. Bypassing validation will miss that conflict. What I've done in my projects is to customize the validation so that it doesn't check time periods that belong to the record currently being validated. That will ignore conflicts with itself, but still check for conflicts with others.



14.9k

Yes, you are right, Dylan, i don't need to skip validation, sorry for misguiding into my issue.

What i have done, is, i am using $model->getOperationMade() (in my custom Validator) to identify the operation that is currently being processed. ( not sure why this operation is called _OperationMade :))

and additionally i pass apptID from my Model to my Validator to make sure, that if i update the current appointment that i work with, i skip time validation.