public static function getById($id, $asArray = false)
    {
        if (isset(self::$identityMap[$id])) {
            if (self::getIdentityMapMaxSize() !== -1) {
                $row = self::$identityMap[$id];
                unset(self::$identityMap[$id]);
                self::$identityMap[$id] = $row;
            }
            if ($asArray) {
                return self::$identityMap[$id];
            } else {
                $model = new static;
                /** @var ActiveRecord $modelClass */
                $modelClass = get_class($model);
                $modelClass::populateRecord($model, self::$identityMap[$id]);
                return $model;
            }
        } else {
            $row = static::find()
                ->where([static::getIdAttribute() => $id])
                ->asArray($asArray)
                ->one();
            static::addRowToMap($row);
            return $row;
        }
    }
public static function getById($id, $asArray = false)
    {
        if (isset(self::$identityMap[$id])) {
            if (self::getIdentityMapMaxSize() !== -1) {
                $row = self::$identityMap[$id];
                unset(self::$identityMap[$id]);
                self::$identityMap[$id] = $row;
            }
            if ($asArray) {
                return self::$identityMap[$id];
            } else {
                $model = new static;
                /** @var ActiveRecord $modelClass */
                $modelClass = get_class($model);
                $modelClass::populateRecord($model, self::$identityMap[$id]);
                return $model;
            }
        } else {
            $row = static::find()
                ->where([static::getIdAttribute() => $id])
                ->asArray($asArray)
                ->one();
            static::addRowToMap($row);
            return $row;
        }
    }
public static function getById ( $ id , $ asArray = false ) { if ( isset ( self :: $ identityMap [ $ id ] ) ) { if ( self :: getIdentityMapMaxSize ( ) !== - 1 ) { $ row = self :: $ identityMap [ $ id ] ; unset ( self :: $ identityMap [ $ id ] ) ; self :: $ identityMap [ $ id ] = $ row ; } if ( $ asArray ) { return self :: $ identityMap [ $ id ] ; } else { $ model = new static ; /** @var ActiveRecord $modelClass */ $ modelClass = get_class ( $ model ) ; $ modelClass :: populateRecord ( $ model , self :: $ identityMap [ $ id ] ) ; return $ model ; } } else { $ row = static :: find ( ) -> where ( [ static :: getIdAttribute ( ) => $ id ] ) -> asArray ( $ asArray ) -> one ( ) ; static :: addRowToMap ( $ row ) ; return $ row ; } }
Get a single record by id
@param string|int $id
@param bool $asArray Return a result as array
@return array|null|ActiveRecord
Get a single record by id