Skip to main content
added 206 characters in body
Source Link
ANKIT
  • 161
  • 1
  • 5

Looking at the code of save method in Magento\Framework\Model\ResourceModel\Db, I can see that there is validateBeforeSave method which is being called on model object, so you can be usedoverride _getValidationRulesBeforeSave method in your model where you can provide set of validation rules to validate the currentyour model data. If

Additionally, if validation fails then you can use _dataSaveAllowed flag to stop the saving operation.

Refer Magento\User\Model\User.php for reference.

I hope this helps someone looking for model data validation.

Looking at the code of save method in Magento\Framework\Model\ResourceModel\Db, I can see that there is validateBeforeSave method which can be used to validate the current model data. If validation fails then you can use _dataSaveAllowed flag to stop the saving operation.

I hope this helps someone looking for data validation.

Looking at the code of save method in Magento\Framework\Model\ResourceModel\Db, I can see that there is validateBeforeSave method which is being called on model object, so you can override _getValidationRulesBeforeSave method in your model where you can provide set of validation rules to validate your model.

Additionally, if validation fails then you can use _dataSaveAllowed flag to stop the saving operation.

Refer Magento\User\Model\User.php for reference.

I hope this helps someone looking for model data validation.

Source Link
ANKIT
  • 161
  • 1
  • 5

Looking at the code of save method in Magento\Framework\Model\ResourceModel\Db, I can see that there is validateBeforeSave method which can be used to validate the current model data. If validation fails then you can use _dataSaveAllowed flag to stop the saving operation.

I hope this helps someone looking for data validation.