3

Let say that we have two tables: Post and Category and two posts that have the same category_id, let say 1.

$post1->getCategory()->getName() will load the category that has category_id 1

$post2->getCategory()->getName() will do the same query to load the same category.

Is there any solution do not make the same query twice?

Alin
  • 267
  • 4
  • 15

1 Answers1

1

I might be wrong but I believe Doctrine will make use of internal cache to optimize this kind of queries. AFAIK it will keep a pool of objects used by your application, so the first time the category is loaded (post1) it will keep an internal reference of that object in its cache so the second time the same category is invoked it will return the previous instance used instead of making a new query to the database.

markdrake
  • 624
  • 7
  • 12