Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with QueryBuilder #87

Open
FredDut opened this issue Jun 19, 2022 · 1 comment
Open

Problem with QueryBuilder #87

FredDut opened this issue Jun 19, 2022 · 1 comment

Comments

@FredDut
Copy link

FredDut commented Jun 19, 2022

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?

@zanbaldwin
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants