like in symfony's query builder doesn't work and show me error!
this is my query:
$apiToken = $this->createQueryBuilder('ud')
->select('ud.apiToken')
->where('ud.user LIKE :userPhone')
->setParameter('userPhone','%'.$phone)
->getQuery()
->getResult();
return $apiToken;
and this is the error:
[Semantical Error] line 0, col 64 near 'user LIKE :u': Error: Invalid PathExpression. Must be a StateFieldPathExpression.
cant find any extension stuff for like in query builder or useful description!
this is my UserDevice Entity:
class UserDevice implements UserInterface, \Serializable
{
/**
* @var int
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(name="notification_token",type="string", nullable=true)
*/
private $notificationToken;
/**
* @ORM\Column(name="api_token" , type="string", unique=true, nullable=true)
*/
private $apiToken;
/**
* @ORM\OneToOne(targetEntity="User", inversedBy="device", fetch="EAGER")
* @ORM\JoinColumn(name="user_phone", referencedColumnName="phone")
*/
private $user;
}
You should use join
query between table UserDevice
and User
.
$apiToken = $this->createQueryBuilder('ud')
->select('ud.apiToken')
->where('u.phone LIKE :userPhone') // here Users phone field
->innerJoin('ud.user', 'u')
->setParameter('userPhone','%'.$phone)
->getQuery()
->getResult();
return $apiToken;