0

I have a LibPhoneNumber object $phone I pass to a repository method. In my repository method I have:

    return $this->getEntityManager()
        ->createQuery(
            'SELECT p, m FROM AppBundle:Phone p JOIN p.member m WHERE p.phoneNumber = :phone AND m.allowFind = TRUE'
        )
        ->setParameter("phone", $phone)
        ->getOneOrNullResult();

The problem is the query that is being generated and run literally inserts 'Object(libphonenumber\PhoneNumber)'

WHERE p0_.phone_number = 'Object(libphonenumber\\PhoneNumber)' AND m1_.allow_find = 1

if I use the default repository method findOneByPhoneNumber($phone) it correctly converts the phone number into the format in which it is stored in the database +14565551212

snoop168
  • 394
  • 3
  • 16

1 Answers1

0

So I think I figured it out... Looks like for some reason I need to make the conversion manually while for some reason the built in findOneByxxxxx() method does it automatically some how. Maybe someone could comment on that?

Either way, I made the conversion manually by doing:

    $phoneNumberUtil = PhoneNumberUtil::getInstance();
    $number = $phoneNumberUtil->format($phone, \libphonenumber\PhoneNumberFormat::E164);

and then passing $number into the setParameter("phone". $number) method instead of $phone which was the object.

snoop168
  • 394
  • 3
  • 16