I am developing an application with Symfony2 and Doctrine and have a status table in which I store location and date files, for example:
ID | Book | Date | Location ------------------------------------------------ 1 | Book_1 | 2011-08-29 | Home 2 | Book_1 | 2011-08-30 | Office 3 | Book_1 | 2011-09-02 | Friend House 4 | Book_2 | 2011-09-02 | Office 5 | Book_2 | 2011-09-04 | Home
A status record with the most recent date represents the current (or last known) location of this book. In the above example, Book_1 is currently in "Friend House", and Book_2 is in "Home".
The following code retrieves any entries that at some point had a Home location:
$em = $this->getEntityManager(); $query = $em->createQuery('SELECT s FROM myBookTestBundle:Status s WHERE s.location=:x')->setParameter('x', 'Home'); $status = $query->getResult();
Instead, Iβd like to select only those books whose current location is the same as Home. In the above example, this will be only the record identifier = 5 (Book_2).
Is there any way to do this with DQL?
Any help is greatly appreciated.
Thanks,
Ralph
source share