public static function addRowsToMap($rows)
    {
        $firstRow = reset($rows);
        $idAttribute = static::getIdAttribute();
        if ($firstRow instanceof ActiveRecord) {
            foreach ($rows as $row) {
                self::$identityMap[$row[$idAttribute]] = $row->toArray();
                foreach (static::getUniqueAttributes() as $uniqueAttribute) {
                    self::$uniqueAttributeToId[$uniqueAttribute][$row[$uniqueAttribute]] = $row[$idAttribute];
                }
            }
        } else {
            foreach ($rows as $row) {
                self::$identityMap[$row[$idAttribute]] = $row;
                foreach (static::getUniqueAttributes() as $uniqueAttribute) {
                    self::$uniqueAttributeToId[$uniqueAttribute][$row[$uniqueAttribute]] = $row[$idAttribute];
                }
            }
        }
        $maxSize = self::getIdentityMapMaxSize();
        if ($maxSize !== -1) {
            $count = count(self::$identityMap);
            if ($count > $maxSize) {
                self::$identityMap = array_slice(
                    self::$identityMap,
                    $count - $maxSize,
                    $maxSize
                );
            }
        }
    }