0

I follow this tutorial on how to generate Doctrine Repositories.

My entity Event:

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\Validator\Constraints as Assert;
use Gedmo\Mapping\Annotation as Gedmo;

/**
 * Class Event
 * @package AppBundle\Entity
 * @ORM\Entity(repositoryClass="AppBundle\Repository\EventRepository")
 * @ORM\Table(name="event")
 */
class Event
{
    /**
     * @ORM\Column(type="guid")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="UUID")
     */
    private $uuid;

    /**
     * @ORM\Column(type="string", length=100)
     * @Assert\NotBlank(message="parameter ""name"" should not be blank")
     */
    private $name;

    /**
     * @Assert\NotBlank(message="parameter ""description"" should not be blank")
     * @ORM\Column(type="text")
     */
    private $description;

    /**
     * @Assert\NotBlank(message="parameter ""startDate"" should not be blank")
     * @Assert\DateTime(message="parameter ""startDate"" expects format of Y-m-d H:i:s")
     * @ORM\Column(type="datetime")
     * @Serializer\Type("DateTime<'Y-m-d H:i:s'>")
     */
    private $startDate;

    /**
     * @Assert\NotBlank(message="parameter ""endDate"" should not be blank")
     * @Assert\DateTime(message="parameter ""endDate"" expects format of Y-m-d H:i:s")
     * @ORM\Column(type="datetime")
     * @Serializer\Type("DateTime<'Y-m-d H:i:s'>")
     */
    private $endDate;

    // getters and setters left out

}

Following the tutorial above, I run

php bin/console doctrine:generate:entities AppBundle

My expectation would be it generates a repository class EventRepository. Instead, it creates this:

namespace AppBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class AppBundle extends Bundle
{
}

I thought the generator would inspect the repositoryClass annotation in order to determine which class to generate. I tried using

php bin/console doctrine:generate:entities AppBundle:Event

instead. Did not work.

I know I can just write the class myself, I merely wonder whether I use the generator wrong or just don't get the documentation.

Chrisissorry
  • 1,434
  • 2
  • 22
  • 43

1 Answers1

2

You can find the answer here:

Link to answer

If you have already generated your entity class before adding the repositoryClass mapping, you have to create the class on your own. Fortunately, it’s pretty easy. Simply create the class in the Repository directory of your bundle and be sure it extends Doctrine\ORM\EntityRepository. Once you’ve created the class, you can add any method to query your entities.

Community
  • 1
  • 1
ZugZwang
  • 418
  • 1
  • 5
  • 14