Skip validation unchanged attributes

Hello enybody

When calling $user->save() before update checking model rules. If model has unique rule this was execute query to DB if this attribute not changed.

In ActiveRecord::update called validate and then in updateInternal method taking only changed attributes by $values = $this->getDirtyAttributes($attributes);

maybe do something like this in ActiveRecord

public function update($runValidation = true, $attributeNames = null)
{
	if ($runValidation && !$this->validate($attributeNames)) {
        Yii::info('Model not updated due to validation error.', __METHOD__);
        return false;
    }

    if (!$this->isTransactional(self::OP_UPDATE)) {
        return $this->updateInternal($attributeNames);
    }

add

public function update($runValidation = true, $attributeNames = null)
{
	$attributeNames = array_keys($this->getDirtyAttributes($attributeNames));

    if ($runValidation && !$this->validate($attributeNames)) {
        Yii::info('Model not updated due to validation error.', __METHOD__);
        return false;
    }

    if (!$this->isTransactional(self::OP_UPDATE)) {
        return $this->updateInternal($attributeNames);
    }

So far, just a suggestion, I have not yet tried to do this and run tests

What do you think about this?

In my case TimestampBehavior did not work.

Is a bad idea to do in ActiveRecord ? :

public function update($runValidation = true, $attributeNames = null)
{
    if ($runValidation && !$this->validate(array_keys($this->getDirtyAttributes($attributeNames)))) {
        Yii::info('Model not updated due to validation error.', __METHOD__);
        return false;
    }

    if (!$this->isTransactional(self::OP_UPDATE)) {
        return $this->updateInternal($attributeNames);
    }

Or it would be better to override in a model

public function validate($attributeNames = null, $clearErrors = true)
{
    return parent::validate(array_keys($this->getDirtyAttributes($attributeNames)), $clearErrors);
}