private function _deletePk(array $args = [])
{
$iterator = $this->getIterator();
$pk = $iterator->getPrimaryKey();
if (empty($pk)) {
throw new ModelException(sprintf("Primary key has not been defined with @Id tag for %s", get_class($this)));
}
if (count($args) != count($pk)) {
throw new InvalidArgumentException(sprintf("The number of arguments passed does not match the primary key fields (%s)", join(', ', $pk)));
}
$stmtWhere = [];
$arguments = [];
foreach ($pk as $pos => $fieldName) {
$field = $iterator->getField($fieldName);
$value = $args[$pos];
if (!isset($value) && $field->column->nullable) {
$stmtWhere[] = "{$field->getColumnName()} IS NULL";
} else {
$stmtWhere[] = "{$field->getColumnName()} = {$field->type->wh()}";
$arguments[] = $field->type->toDb($value);
}
}
$stmtWhere = implode(' AND ', $stmtWhere);
$this->db()->Execute("\n DELETE FROM {$this->table()}\n WHERE {$stmtWhere} LIMIT 1\n ", $arguments);
return $this->db()->_affectedrows();
}