public function afterSave($event)
    {
        if (!$this->enableAuditField) {
            parent::afterSave($event);
            return;
        }

        $date = time();
        $newAttributes = $this->owner->attributes;
        $oldAttributes = $this->_dbAttributes;
        $auditModels = $this->getAuditModels();
        $auditRequestId = $this->getAuditRequestId();
        $auditFields = array();
        $userId = Yii::app()->user && Yii::app()->user->id ? Yii::app()->user->id : 0;

        // insert
        if ($this->owner->isNewRecord) {
            foreach ($newAttributes as $name => $new) {
                if (in_array($name, $this->ignoreFields['insert'])) continue;

                // prepare the values
                $new = trim($new);
                if (!$new) continue;

                // prepare the logs
                foreach ($auditModels as $auditModel) {
                    if (isset($auditModel['ignoreFields']) && in_array($name, $auditModel['ignoreFields'])) continue;
                    $auditFields[] = array(
                        'old_value' => '',
                        'new_value' => $new,
                        'action' => 'INSERT',
                        'model_name' => $auditModel['model_name'],
                        'model_id' => $auditModel['model_id'],
                        'field' => $auditModel['prefix'] . $name,
                        'created' => $date,
                        'user_id' => $userId,
                        'audit_request_id' => $auditRequestId,
                    );
                }
            }
        }

        // update
        else {
            // compare old and new
            foreach ($newAttributes as $name => $new) {
                if (in_array($name, $this->ignoreFields['update'])) continue;

                // prepare the values
                $old = !empty($oldAttributes) ? trim($oldAttributes[$name]) : '';
                $new = trim($new);
                if (in_array($old, $this->ignoreValues)) $old = '';
                if (in_array($new, $this->ignoreValues)) $new = '';
                if ($new == $old) continue;

                // prepare the logs
                foreach ($auditModels as $auditModel) {
                    if (isset($auditModel['ignoreFields']) && in_array($name, $auditModel['ignoreFields'])) continue;
                    $auditFields[] = array(
                        'old_value' => $old,
                        'new_value' => $new,
                        'action' => 'UPDATE',
                        'model_name' => $auditModel['model_name'],
                        'model_id' => $auditModel['model_id'],
                        'field' => $auditModel['prefix'] . $name,
                        'created' => $date,
                        'user_id' => $userId,
                        'audit_request_id' => $auditRequestId,
                    );
                }
            }
        }

        // insert the audit_field records
        $this->addAuditFields($auditFields);

        // set the dbAttributes to the new values
        $this->_dbAttributes = $this->owner->attributes;

        parent::afterSave($event);
    }