Setting a Doctrine query limit in Sensio Lab’s Symfony PHP framework for customer queries in respositories

Here is an example of a simple DQL query in a custom repository method meant to return a single array result. The following will return the latest result in case there are multiple contact records that match the “customerId” field, which is actually “customer_id” in the database, but remember that camelCase convention applies to Doctrine mappings of database fields.

Note: Using Symfony’s built-in repository method findBy() is possible here, but with multiple “WHERE” conditions, this approach is usually more flexible.

Aaron Belchamber has written 243 articles

Leave a Reply

Your email address will not be published. Required fields are marked *