0

I would like to know what it is preferable for the optimisation between 2 approachs in ORM.

  • I create a QueryBuilder with conditions of my object and get an array of the Objects respecting my conditions of queries
  • and get all Objects with getDoctrine()->findAll() and then check in php the conditions that I applied on my objects

I wonder it especially in the case of hotel booking and the availbility of some rooms. This kind of search includes a lot of different entities with complex queries. Just thinking about the querybuilder makes me an headache... But i'm not sure that's the best way to populate all entites in php and then apply my functions....

2
  • I don't really understand the question. The common pattern is to have a service class who you can call to get entities that match a certain type. e.g. $rooms = $bookingService->getUnbookedRoomsForDateRange($datetime1, $datetime2). What you do inside that function is up to you (use DQL, a query builder, SQL or pull it in via a webservice...) Commented Jan 19, 2012 at 16:00
  • I don't understand the question either. Commented Jan 19, 2012 at 18:14

2 Answers 2

1

Generally you should be getting the objects you require via queries built using the query builder. You should not get all your entities via ->findAll() and then filtering with php as this could be very resource intensive - imagine you had 1,000,000 entries in your database?

If you were looking at hotel bookings and room availability - you would write a query that only returns objects that have room availability - rather than checking all objects with php.

I wrote a blog post on some best practices with doctrine which can be found here - http://www.uvd.co.uk/blog/some-doctrine-2-best-practices/

Sign up to request clarification or add additional context in comments.

Comments

0

I think it's allways better to create an QueryBuilder (or simply write a DQL query) to get your results.

When you get all your objects with a getDoctrine()->findAll() call, a PHP object is created and his values are set for every result. Then your PHP script (which is certainly slower than the database) will only keep interesting objects, you will have a lot of garbadge.

When you use a QueryBuilder, the database optimizes your query's processing and returns only the interesting objects. You avoid a lots of object instanciation and don't need to filter results with PHP.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.