/** * Deletes document with the specified primary key. * See {@link find()} for detailed explanation about $condition and $params. * @param mixed $pkValue primary key value(s). Use array for multiple primary keys. For composite key, each key value must be an array (column name=>column value). * @param array|CriteriaInterface $criteria query criteria. * @since v1.0 */ public function deleteByPk($pkValue, $criteria = null) { if ($this->_beforeDelete()) { $criteria = $this->sm->apply($criteria); $criteria->mergeWith(PkManager::prepare($this->model, $pkValue)); $result = $this->getCollection()->remove($criteria->getConditions(), $this->options->getSaveOptions(['justOne' => true])); return $this->_result($result); } return false; }
/** * Finds document with the specified primary key. Primary key by default * is defined by `_id` field. But could be any other. For simple (one column) * keys use it's value. * * For composite use key-value with column names as keys * and values for values. * * Example for simple pk: * ```php * $pk = '51b616fcc0986e30026d0748' * ``` * * Composite pk: * ```php * $pk = [ * 'mainPk' => 1, * 'secondaryPk' => 2 * ]; * ``` * * @param mixed $pkValue primary key value. Use array for composite key. * @param array|CriteriaInterface $criteria * @return AnnotatedInterface|null * @Ignored */ public function findByPk($pkValue, $criteria = null) { $pkCriteria = new Criteria($criteria); $pkCriteria->decorateWith($this->model); $pkCriteria->mergeWith(PkManager::prepare($this->model, $pkValue)); return $this->find($pkCriteria); }