ip icon indicating copy to clipboard operation
ip copied to clipboard

Problem with QueryBuilder

Open FredDut opened this issue 2 years ago • 1 comments

Hello, I'm facing a problem with querybuilder (Symfony 5.4): I've created a basic entity:

/**
 * @ORM\Entity(repositoryClass=JustipRepository::class)
 */
class Justip
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="ip", nullable=true)
     */
    private $ip;

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getIp()
    {
        return $this->ip;
    }

    public function setIp($ip): self
    {
        $this->ip = $ip;

        return $this;
    }
}

in my controller

$ip = Multi::factory('192.168.0.1');

if use the magic method , it 's ok $entities = $this->em->getRepository(Justip::class)->findByIp($ip->getBinary());

if use the querybuilder it's not ok

  public function findByExampleField($value): array
   {
       return $this->createQueryBuilder('j')
           ->andWhere('j.ip = :val')
           ->setParameter('val', $value)
           ->getQuery()
           ->getResult()
       ;
   }

$entities = $this->em->getRepository(Justip::class)->findByExampleField($ip->getBinary());

With findByIp , the runable query is SELECT j0_.id AS id_0, j0_.ip AS ip_1 FROM justip j0_ WHERE j0_.ip = \0x00000000000000000000FFFFC0A80001;

With querybuilder the runable query is SELECT j0_.id AS id_0, j0_.ip AS ip_1 FROM justip j0_ WHERE j0_.ip = 0x00000000000000000000FFFFC0A80001;

I don't know how to tell doctrine that the binary value is binary. Is there something wrong in my code?

FredDut avatar Jun 19 '22 09:06 FredDut

Hi, thanks for reporting this - I'll take a look at this and get back to you!

zanbaldwin avatar Jun 22 '22 15:06 zanbaldwin