website/errors/doctrine.findOneByArgument.md
<?php declare(strict_types = 1);
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
class User
{
#[ORM\Id]
#[ORM\Column]
private int $id;
#[ORM\Column]
private string $email;
}
<?php declare(strict_types = 1);
/** @var \Doctrine\ORM\EntityRepository<User> $repository */
$user = $repository->findOneBy(['username' => 'john']);
This error is reported by the phpstan-doctrine extension.
The criteria array passed to findOneBy() contains a key (username) that does not correspond to any field or association on the entity (User). This likely indicates a typo or a reference to a field that does not exist.
When bleeding edge is enabled, the field names in the second argument (the order-by array) are checked the same way:
$repository->findOneBy(['email' => '[email protected]'], ['username' => 'ASC']);
Use a field name that exists on the entity:
<?php declare(strict_types = 1);
/** @var \Doctrine\ORM\EntityRepository<User> $repository */
-$user = $repository->findOneBy(['username' => 'john']);
+$user = $repository->findOneBy(['email' => '[email protected]']);
The same applies to the order-by argument:
-$user = $repository->findOneBy(['email' => '[email protected]'], ['username' => 'ASC']);
+$user = $repository->findOneBy(['email' => '[email protected]'], ['email' => 'ASC']);