30/05/2015 - DOCTRINE
These are some facts about doctrine and the list will grow when time goes by. Note: If you're using symfony framework make sure you're using profiler bar because it gives us a lot of information about queries run.
createQueryBuilder()
in repository classes if the targeted entity has associations with others because, depending on what you’re doing doctrine lazy load might kick in and run additional queries for associations later on so it is better to select all associations with leftJoin()
up front.find
methods for fetching record(s) is better option since it uses slightly less memory and takes shorter to run.leftJoin()
with createQueryBuilder()
in repository class....->getQuery()...->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true)...->getResult();
method to your query builder.Query#iterate()
in your QueryBuilder to avoid loading the whole result into memory at once. For more info, click here.