Answer the question
In order to leave comments, you need to log in
How to search on a relational field in Doctrine?
Making a query to the database
$query = $records->createQueryBuilder('d')
->orderBy('d.id', 'ASC')
->where('d.version_id = :version')
->setParameter('version', $version)
->getQuery();
$query = $records->createQueryBuilder('d')
->orderBy('d.id', 'ASC')
->getQuery();
Answer the question
In order to leave comments, you need to log in
When you work with an ORM and write queries with a query builder (or DQL), there is no such thing as a "column" for you. You are working with mapping tables to entities. Therefore, you have entity fields at your disposal. In the query builder, you are accessing the fields of an entity, not the columns of a table. To refer to the foreign key of an entity (for example, to make a condition without a relation join), the IDENTITY() function built into DQL is used. In your case it will look something like this:
$query = $records->createQueryBuilder('d')
->orderBy('d.id', 'ASC')
->where('IDENTITY(d.version) = :version')
->setParameter('version', $version)
->getQuery();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question