/** * @inheritdoc */ public function rules() { return array_merge(parent::rules(), [[['db', 'ns', 'collectionName', 'databaseName', 'attributeList', 'modelClass', 'baseClass'], 'filter', 'filter' => 'trim'], [['ns'], 'filter', 'filter' => function ($value) { return trim($value, '\\'); }], [['db', 'ns', 'collectionName', '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.'], [['collectionName'], 'match', 'pattern' => '/^[^$ ]+$/', 'message' => 'Collection name can not contain spaces or "$" symbols.'], [['databaseName'], 'match', 'pattern' => '/^[^\\/\\\\\\. "*:?\\|<>]+$/', 'message' => 'Database name can not contain spaces or any of "/\\."*<>:|?" symbols.'], [['db'], 'validateDb'], [['ns'], 'validateNamespace'], [['collectionName'], 'validateCollectionName'], [['attributeList'], 'match', 'pattern' => '/^(\\w+\\,[ ]*)*([\\w]+)$/', 'message' => 'Attributes should contain only word characters, and should be separated by coma.'], [['modelClass'], 'validateModelClass', 'skipOnEmpty' => false], [['baseClass'], 'validateClass', 'params' => ['extends' => ActiveRecord::className()]], [['enableI18N'], 'boolean'], [['messageCategory'], 'validateMessageCategory', 'skipOnEmpty' => false]]); }
/** * Returns a value indicating whether the given active record is the same as the current one. * The comparison is made by comparing the collection 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 Mongo collection. */ public function equals($record) { if ($this->isNewRecord || $record->isNewRecord) { return false; } return $this->collectionName() === $record->collectionName() && (string) $this->getPrimaryKey() === (string) $record->getPrimaryKey(); }