Skip to content

Problem with QueryBuilder #87

@FredDut

Description

@FredDut

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions