Mautic Community Forums

Create an entity on mautic for a plugin

Hello everyone.
I have created a simple starting pulgin. I am now stuck creating my mautic default database table.
I have created my entity and my repository, on symfony I have a command to create the table, but on mautic how is it created? I tried updating the plugin but nothing just isn’t created. Suggestions?

I created an entity based on symfony knowledge but sending the command to create the table with columns gives me this error.

$ php bin/console doctrine:schema:update --dump-sql

In MappingException.php line 56:

No identifier/primary key specified for Entity “MauticPlugin\MauticDemoBundle\Entity\Demo” sub class of “Mautic\CoreBundle\Entity\CommonEntity”. Every Entity must have an identifier/primary key.

The key id is set like this →

class Demo extends CommonEntity

{

/** @Id @Column(type="integer") */

private $id;

/**

 * @var string

 * @ORM\Column(type='string' , lenght='255)

 */

private $name;

/**

 * @var string

 * @ORM\Column(type='string' , lenght='255)

 */

private $surname;

 /**

 * @param ORM\ClassMetadata $metadata

 */

 public static function loadMetadata(ORM\ClassMetadata $metadata): void

 {

    $builder = new ClassMetadataBuilder($metadata);

    $builder

        ->setTable('demo')

        ->setCustomRepositoryClass(DemodRepository::class);

        // $builder->addIdColumns();

        $builder

            ->createField('name' , 'string')

            ->columnName('name')

            ->nullable(false);

        $builder

            ->createField('surname', 'string')

            ->columnName('surname')

            ->nullable(false);

            }

            /**

            * @return mixed

            */

            public function getId(): ?int

            {

                return $this->id;

            }

           

            /**

            * @return mixed

            */

            public function getName(): ?string

            {

                return $this->name;

            }

       

            /**

            * @param mixed $name

            *

            * @return Demo

            */

            public function setName(string $name): self

            {

                $this->name = $name;

       

                return $this;

            }

           

            /**

            * @return mixed

            */

            public function getSurname(): ?string

            {

                return $this->surname;

            }

       

            /**

            * @param mixed $name

            *

            * @return Demo

            */

            public function setSurname(string $surname): self

            {

                $this->brand = $surname;

       

                return $this;

            }

        }