SymfonyCasts / reset-password-bundle

Need a killer reset password feature for your Symfony? Us too!
https://symfonycasts.com
MIT License
477 stars 68 forks source link

Cannot find the entity manager for class "App\Entity\ResetPasswordRequest" #270

Closed astronati closed 1 year ago

astronati commented 1 year ago

After run bin/console make:reset-password and answering some questions I get following error:

Cannot find the entity manager for class "App\Entity\ResetPasswordRequest"

bocharsky-bw commented 1 year ago

Do you have a few entity managers configured in your project? Did you try to clear the cache, Is the error still the same?

Btw, could you dobule check the ResetPasswordRequest entity, the properties inside should be declared with PHP attributes. Do you also use PHP attributes for your other entities? Or use annotations? You can't use both, so you would need to sync it.

astronati commented 1 year ago

Hi @bocharsky-bw,

The entity follows:

<?php

namespace App\Entity;

use App\Repository\ResetPasswordRequestRepository;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity(repositoryClass: ResetPasswordRequestRepository::class)]
class ResetPasswordRequest
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    public function getId(): ?int
    {
        return $this->id;
    }
}

I understood what happened: the problem is due to the fact the entities in my project are under src\Domain\Entity and this bundle I suppose consider only entities under src\Entity, in fact the make command exits with error due to the fact it cannot find some files.

THE SOLUTION Changing doctrine.yaml as follows it worked

doctrine:
    orm:
        mappings:
            App:
                is_bundle: false
                dir: '%kernel.project_dir%/src/'
                prefix: 'App'
                alias: App
bocharsky-bw commented 1 year ago

Yes, the bundle is supposed your entities are following the default src/Entity/ dir. So, I think you just need to move the new entity in the proper dir and fix namespaces everywhere. Actually, the Maker bundles is supposed to generate entities in the default src/Entity/ too. So, if you're not using a standard path - you need to do some extra work after files are generated.

Thanks for sharing your solution with others! Can we close this issue now?

astronati commented 1 year ago

Yes, even if I would suggest to use the path set in the configuration.

Thanks.

bocharsky-bw commented 1 year ago

Unfortunately, we just follow the logic of make:entity command - that command also does not allow you to set up a different folder (mostly for simplicity reasons I suppose). So the issue is not directly related to this repo. But I'm happy to hear you found a workaround on it

astronati commented 1 year ago

Thanks @bocharsky-bw ! ;)