Hym/WebBundle/Entity/Company.php
<?php
namespace Hym\WebBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="Hym\WebBundle\Repository\CompanyRepository")
*/
class Company {
//.....................
I run this command:
php app/console doctrine:generate:entities HymWebBundle
Then I get:
Generating entities for bundle "HymWebBundle"
> backing up Company.php to Company.php~
> generating Hym\WebBundle\Entity\Company
Repository file has not been generated.
So I did some check on
vendor/doctrine/doctrine-bundle/Doctrine/Bundle/DoctrineBundle/Command/GenerateEntitiesDoctrineCommand.php
var_dump($m->customRepositoryClassName);
var_dump($metadata->getNamespace());
var_dump(false !== strpos($m->customRepositoryClassName, $metadata->getNamespace()));
if ($m->customRepositoryClassName && false !== strpos($m->customRepositoryClassName, $metadata->getNamespace())) {
$repoGenerator->writeEntityRepositoryClass($m->customRepositoryClassName, $metadata->getPath());
}
and run again,I got this:
Generating entity "Hym\WebBundle\Entity\Company"
> backing up Company.php to Company.php~
> generating Hym\WebBundle\Entity\Company
string(42) "Hym\WebBundle\Repository\CompanyRepository"
string(20) "Hym\WebBundle\Entity"
bool(false)
Obviously "false !== strpos($m->customRepositoryClassName, $metadata->getNamespace())" will be false.
and the function writeEntityRepositoryClass will not be running.
I thought That may a bug ?
I have the same issue, Is there any update on this issue. How to resolve
It seems that doctrine demands that the repository class is in the entity directory...
quick fix is to ommit the false !== repository_class_is_in_the_entity_directory condition
so, result is?
select HymWebBundle\Repository\CompanyRepository then press alt+enter choose create doctrine repository class
you will find CompanyRepository.php file created either in entity folder or repository folder based upon your configuration.
Closing as this seems fixed since quite a while
Not working on Symfony 3.3 and 3.4: repository classes are not created by app/console doctrine:generate:entities.
And orm:generate-repositories command is not available...
The functionality was moved in the makerBundle I think.
IMHo this issue should be reopened
When I generated entities with
php bin/console doctrine:mapping:import 'App\Entity' annotation --path=src/Entity
all of them are generated with an empty Entity annotation like this:
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* MyTable
*
* @ORM\Table(name="my_table")
* @ORM\Entity()
*/
class MyTable
// ...
Then when I use the maker (php bin/console make:entity --regenerate App), of course it won't generate the Repository class because there is any specified. The expected imported entity should look like this:
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* MyTable
*
* @ORM\Table(name="my_table")
* @ORM\Entity(repositoryClass="App\Repository\MyTableRepository")
*/
class MyTable
// ...
Conclusion, the doctrine import command should have an option to add the repositoryClass.
I suggest to add the --with-repositories, --repository-namespace, --repository-suffix options.
Most helpful comment
IMHo this issue should be reopened
When I generated entities with
php bin/console doctrine:mapping:import 'App\Entity' annotation --path=src/Entityall of them are generated with an empty Entity annotation like this:
Then when I use the maker (
php bin/console make:entity --regenerate App), of course it won't generate the Repository class because there is any specified. The expected imported entity should look like this:Conclusion, the doctrine import command should have an option to add the
repositoryClass.I suggest to add the
--with-repositories,--repository-namespace,--repository-suffixoptions.