yiisoft / validator

Yii validator library
https://www.yiiframework.com/
BSD 3-Clause "New" or "Revised" License
113 stars 39 forks source link

[2.1|3.0] proposal ActiveRecords class without validation first #14

Closed Insolita closed 4 years ago

Insolita commented 6 years ago

In some simple cases internal model validation not bad, but in more complex cases when validation is in separate classes and save/update operations wrapped into services/repositories, validation-scenario functional seems like overhead and thereare reasons for prohibit direct usage of $model->load($data) && $model->validate() and internal rules configuration;

So my proposal - extract validation feature in trait and add something like SelfValidationInterface, instead of BaseActiveRecord extends Model

samdark commented 6 years ago

In general entity should validate data that is set into it. If you don't need it for some reason, you can pass false to save(). But maybe I don't get what the issue is... worth elaborating.

Insolita commented 6 years ago

There are not technical issue, it's more about architecture. A lot of controversy about where to make the validation. I think this should be discussed. (I`ve troubles with access to facebook discussion)

samdark commented 6 years ago

Usually entity validates itself and there could be more validation added in the layers wrapping it. These layers have an ability to disable entity validation. It all depends on the use case.

dynasource commented 6 years ago

it makes sense to disentangle ActiveRecord from Model. It shortens the inheritance tree and separates responsibilities

samdark commented 4 years ago

Out of scope of this package.