protected function normalizeValue($item, $fromDb = false)
    {
        $entityClass = $this->entityClass;
        $itemEntity = null;

        // $item can be an array of data or AbstractEntity
        if ($this->isInstanceOf($item, $entityClass)) {
            return $item;
        }

        if ($this->isArray($item) || $this->isArrayObject($item)) {
            if (isset($item['id'])) {
                // Try getting the instance from cache
                $itemEntity = Entity::getInstance()->get($entityClass, $item['id']);
                if ($itemEntity) {
                    return $itemEntity;
                }

                // If not found in cache, load from database
                $itemEntity = $entityClass::findById($item['id']);
            }
        }

        // If instance was not found, create a new entity instance
        if (!$itemEntity) {
            $itemEntity = new $entityClass;
        }

        // If $item is an array - use it to populate the entity instance
        if ($this->isArray($item) || $this->isArrayObject($item)) {
            if ($fromDb) {
                $item['__webiny_db__'] = true;
            }

            $itemEntity->populate($item);
        }

        return $itemEntity;
    }