yii\db\BaseActiveRecord::getOldPrimaryKey PHP Method

getOldPrimaryKey() public method

This refers to the primary key value that is populated into the record after executing a find method (e.g. find(), findOne()). The value remains unchanged even if the primary key attribute is manually assigned with a different value.
public getOldPrimaryKey ( boolean $asArray = false ) : mixed
$asArray boolean whether to return the primary key value as an array. If `true`, the return value will be an array with column name as key and column value as value. If this is `false` (default), a scalar value will be returned for non-composite primary key.
return mixed the old primary key value. An array (column name => column value) is returned if the primary key is composite or `$asArray` is `true`. A string is returned otherwise (null will be returned if the key value is null).
    public function getOldPrimaryKey($asArray = false)
    {
        $keys = $this->primaryKey();
        if (empty($keys)) {
            throw new Exception(get_class($this) . ' does not have a primary key. You should either define a primary key for the corresponding table or override the primaryKey() method.');
        }
        if (!$asArray && count($keys) === 1) {
            return isset($this->_oldAttributes[$keys[0]]) ? $this->_oldAttributes[$keys[0]] : null;
        } else {
            $values = [];
            foreach ($keys as $name) {
                $values[$name] = isset($this->_oldAttributes[$name]) ? $this->_oldAttributes[$name] : null;
            }
            return $values;
        }
    }