This is because LIMIT works with database rows, not with "objects". When you enter $q->limit(10) , you want to get ten objects, not ten rows from the database.
Consider the following query (products and categories are many-to-many):
SELECT p.*, c.* FROM product p INNER JOIN product_category_ref pcr ON p.id = pcr.prodcut_id INNER JOIN category c ON c.id = pcr.category_id WHERE p.price < 123;
To receive 10 products (objects), your request will have to receive at least 20 lines. You cannot use the reason LIMIT 10 (for example, only), only 3 products will be returned. That's why you need to find out which products should be obtained (the restriction applies to products), and then extract the actual data.
This will result in the following queries:
SELECT p.id FROM product p WHERE p.price < 123; SELECT ..... WHERE p.id IN (...);
The second request can return 20, 423 or 31 lines. As you can see, this is not the value from limit() .
PS. Doctrine2 is much more clear in this case, as it uses the setMaxResults() method instead of limit() , which is less confusing.
Crozin
source share