Class … sub class of … is not a valid entity or mapped super class

Rudolf247
Člen | 38
+
0
-

Volám z presenteru $user = $this->discordUserService->getUserByDiscordId($discordUser[‚id‘]); a dostávám hlášku:

{"fault":{"error":"Class \"App\\Portal\\Database\\User\\UserRepository\" sub class of \"App\\Model\\Database\\Repository\\AbstractRepository\" is not a valid entity or mapped super class."}}

Přesto se mi zdá že mám vše správně. I když dám:
orm:mapping:describe ‚App\Portal\Database\User\User‘

------------------------------- -----------------------------------------
 Field                           Value
------------------------------- -----------------------------------------
 Name                            App\Portal\Database\User\User
 Root entity name                App\Portal\Database\User\User
 Custom generator definition     None
 Custom repository class         App\Portal\Database\User\UserRepository

User entita:

<?php declare(strict_types = 1);

namespace App\Portal\Database\User;

use App\Model\Database\Entity\TCreatedAt;
use App\Model\Database\Entity\TId;
use App\Model\Database\Entity\TUpdatedAt;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Table;


#[Entity(repositoryClass: UserRepository::class)]
#[Table(name: 'users')]
class User
{....
<?php declare(strict_types = 1);

namespace App\Services;

use App\Model\Database\EntityManagerDecorator;
use App\Portal\Database\User\User;
use App\Portal\Database\User\UserRepository;

class DiscordUserService
{

    private EntityManagerDecorator $em;

    public function __construct(EntityManagerDecorator $em) {
        $this->em = $em;
    }

    public function getUserByDiscordId(string $discordId): ?User
    {
        return $this->em->getRepository(UserRepository::class)->findOneByDiscordId($discordId);
    }

}

<?php declare(strict_types = 1);

namespace App\Portal\Database\User;

use App\Model\Database\Repository\AbstractRepository;

/**
 * @method User|NULL find($id, ?int $lockMode = NULL, ?int $lockVersion = NULL)
 * @method User|NULL findOneBy(array $criteria, array $orderBy = NULL)
 * @method User[] findAll()
 * @method User[] findBy(array $criteria, array $orderBy = NULL, ?int $limit = NULL, ?int $offset = NULL)
 * @extends AbstractRepository<User>
 */
class UserRepository extends AbstractRepository
{

    public function findOneByDiscordId(string $discordId): ?User
    {
        return $this->findOneBy(['discord_id' => $discordId]);
    }
}
<?php declare(strict_types = 1);

namespace App\Model\Database\Repository;

use Doctrine\ORM\EntityRepository;

/**
 * @phpstan-template TEntityClass of object
 * @phpstan-extends EntityRepository<TEntityClass>
 */
abstract class AbstractRepository extends EntityRepository
{

}
Rudolf247
Člen | 38
+
0
-

Vyřešeno…:

#[MappedSuperclass]
class UserRepository extends AbstractRepository
{....

Editoval Rudolf247 (29. 10. 2023 16:42)