Hi Michal, You need to join in your contact in order to filter it. Instead of following:
SELECT u FROM App\Model\Entities\User u WHERE u.contact.email = :email You should write following instead: SELECT u FROM App\Model\Entities\User u JOIN u.contact c WHERE c.email = :email Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ On 4 June 2014 08:55, Michal Fučík <[email protected]> wrote: > Hi guys, I am new with Doctrine 2 experiences and I have got a problem > with creating queries via DQL. > > Situation: > > Entity User: > > class User { > /** > * @OneToOne(targetEntity = "Contact", cascade={"all"}, > orphanRemoval=true, fetch="EAGER") > * @JoinColumn(name = "contact_fk", referencedColumnName = "id", > nullable = false) > */ > protected $contact; > ... > } > > Entity Contact: > > class Contact { > > /** @ORM\Column(type="string", nullable=false) */ > protected $email; > ... > > (it has no back reference to entity User) > } > > and I need to create query to fetch User via passed email. Following code > doesn't work. I got exception with explanation - [Syntax Error] line 0, > col 55: Error: Expected =, <, <=, <>, >, >=, !=, got '.' > > UserService: > > public function getUserEmail($email) { > $qb = $this->entityManager->createQueryBuilder(); > $qb->select('u') > ->from('App\Model\Entities\User', 'u') > ->where('u.contact.email = :email') > ->setParameter('email', $email); > > return $qb->getQuery()->getResult(); > } > > Did I make any misunderstanding of Doctrine dql? > > Thx for any reply.. > > > > -- > You received this message because you are subscribed to the Google Groups > "doctrine-user" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/doctrine-user. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "doctrine-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/doctrine-user. For more options, visit https://groups.google.com/d/optout.
