1

Reference To This Question

Where one should put the DQL queries? In a service class, or in a controller or maybe in a repository class?

Found a nice article about this, which answers my question. I think it's best to put them in the service class.

How to integrate Doctrine 2 with your Zend Framework application

Community
  • 1
  • 1
Optimus
  • 1,703
  • 4
  • 22
  • 41

1 Answers1

1

This highly depends on what your DQLs are doing:

If you have a Query which is doing work on only one entity type I suggest to create your own Repository class for this entity. The repository class already provides you with the methods for find and findAll, so it would fit there good. Doctrine gives you orm:generate-repositories as CLI tool. Ralph Schindler took this approach as you can see in his example repository.

If you have a Query which affects multiply types of entities, the Service Layer should be the best place to put it.

Samuel Herzog
  • 3,561
  • 1
  • 22
  • 21
  • So looking at the referenced question above, you think best place is the repository then, am I right? – Optimus Feb 15 '11 at 15:43
  • 1
    Yes, I'd do so. My approach: For decoupling reasons my controllers always speak to a Service class. The service class works on the repository and flushes if needed. So it has two dependencies: the Entitymanager and the repository class (which it may resolve itself). – Samuel Herzog Feb 15 '11 at 15:46