Warning: optimistic lock will NOT work in case of updating fields (not attributes) for the runtime indexes!
Since: 2.0
Author: Paul Klimov (klimov.paul@gmail.com)
Inheritance: extends yii\db\BaseActiveRecord
Example #1
0
 /**
  * Returns a value indicating whether the given active record is the same as the current one.
  * The comparison is made by comparing the index names and the primary key values of the two active records.
  * If one of the records [[isNewRecord|is new]] they are also considered not equal.
  * @param ActiveRecord $record record to compare to
  * @return boolean whether the two active records refer to the same row in the same index.
  */
 public function equals($record)
 {
     if ($this->isNewRecord || $record->isNewRecord) {
         return false;
     }
     return $this->indexName() === $record->indexName() && $this->getPrimaryKey() === $record->getPrimaryKey();
 }
Example #2
0
 public function fields()
 {
     $fields = parent::fields();
     return $fields;
 }
Example #3
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return array_merge(parent::rules(), [[['db', 'ns', 'indexName', 'modelClass', 'baseClass'], 'filter', 'filter' => 'trim'], [['ns'], 'filter', 'filter' => function ($value) {
         return trim($value, '\\');
     }], [['db', 'ns', 'indexName', 'baseClass'], 'required'], [['db', 'modelClass'], 'match', 'pattern' => '/^\\w+$/', 'message' => 'Only word characters are allowed.'], [['ns', 'baseClass'], 'match', 'pattern' => '/^[\\w\\\\]+$/', 'message' => 'Only word characters and backslashes are allowed.'], [['indexName'], 'match', 'pattern' => '/^(\\w+\\.)?([\\w\\*]+)$/', 'message' => 'Only word characters, and optionally an asterisk and/or a dot are allowed.'], [['db'], 'validateDb'], [['ns'], 'validateNamespace'], [['indexName'], 'validateIndexName'], [['modelClass'], 'validateModelClass', 'skipOnEmpty' => false], [['baseClass'], 'validateClass', 'params' => ['extends' => ActiveRecord::className()]], [['enableI18N'], 'boolean'], [['useIndexPrefix'], 'boolean'], [['messageCategory'], 'validateMessageCategory', 'skipOnEmpty' => false]]);
 }