I can't find any documentation about named queries in Doctrine2. Please help. Does Doctrine2 have a named queries feature?
相关问题
- Symfony2 Set Controller in the kernelControllerEve
- Webpack Encore: cannot import local dependencies
- Render custom attribute KNP Menu
- Problems with cap deploy a symfony2 project, can
- Allow CORS on symfony 4
相关文章
- Symfony : Doctrine data fixture : how to handle la
- Symfony is linked to the wrong PHP version
- Symfony2: check whether session exists or not
- Is there a way to modify the entity mapping config
- symfony2 form choice and mongodb
- Get random records with Doctrine
- Symfony 3.1 and OneUpUploaderBundle + Blueimp = Up
- Doctrine not finding data on Google App Engine?
I found this question looking for Native Named Query examples, the above answer helped me so I figured I'd share how to do a native named query in the same way.
Add this to the constructor for your entity repository
Here's a clip of my test for this
You can use
NamedQuery - DQL. Example
And call it like
NamedNativeQuery - SQL. More information here: http://docs.doctrine-project.org/en/latest/reference/native-sql.html#named-native-query
Collecting a queries in your EntityRepository, like:
More information here: http://symfony.com/doc/current/book/doctrine.html#custom-repository-classes
Similar topic here: https://groups.google.com/forum/?fromgroups#!topic/doctrine-user/K-D5ta5tZ3Y[1-25]
Maybe you'll be interested by the EntityRepositories where you can create and store complex Doctrine queries, and call theme in your project where you want:
http://symfony.com/doc/current/book/doctrine.html#custom-repository-classes
You can call the functions used internally by annotation notation in the constructor of your repository if you don't want to mess up your entity definition:
You can also replace the
__CLASS__
part of the statement with the namespace and class of your entity likeMyBundle\Entity\CmsUser