Добавить поля для Sonata UserBundle - PullRequest
0 голосов
/ 14 мая 2019

У меня есть вопрос о расширении сущности Sonata UserBundle.Мне нужно добавить больше полей для сущности.Во-первых, я расширил Sonata UserBundle для своего проекта в папке src \ Application \ Sonata \ UserBundle. Затем я попытался добавить эти поля в User Entity, доступные в той же папке:

<?php

namespace App\Application\Sonata\UserBundle\Entity;

use Sonata\UserBundle\Entity\BaseUser as BaseUser;

/**
 * This file has been generated by the SonataEasyExtendsBundle.
 *
 * @link https://sonata-project.org/easy-extends
 *
 * References:
 * @link http://www.doctrine-project.org/projects/orm/2.0/docs/reference/working-with-objects/en
 */
class User extends BaseUser
{
    /**
     * @var int $id
     */
    protected $id;

    /**
     * Get id.
     *
     * @return int $id
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * @var string
     * @ORM\Column(type="string")
     */
    protected $accountType;

    /**
     * @var int
     * @ORM\ManyToOne(targetEntity="App\Entity\Specialty")
     */
    protected $specialty;

    /**
     * Get AccountType
     * @return string
     */
    public function getAccountType()
    {
        return $this->accountType;
    }

    /**
     * Set AccountType
     * @param string $accountType
     * @return $this
     */
    public function setAccountType($accountType)
    {
        $this->accountType = $accountType;

        return $this;
    }

    /**
     * Get Specialty
     * @return int
     */
    public function getSpecialty()
    {
        return $this->specialty;
    }

    /**
     * Set Specialty
     * @param int $specialty
     * @return Specialty
     */
    public function setSpecialty($specialty)
    {
        $this->specialty = $specialty;

        return $this;
    }
}

На fos_user.ymlЯ нанес на карту эту сущность.Но когда я пытаюсь обновить мою схему, запустив эту команду:

php bin/console doctrine:s:u --force

У меня появляется сообщение о том, что Ничего не обновляется - ваша база данных уже синхронизирована с метаданными текущего объекта.

Добавленное поле не добавлено в мою таблицу.Я не специалист по Symfony, поэтому я попытался объяснить свою ситуацию как можно лучше.

Специальность:

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Table(name="specialties")
 * @ORM\Entity
 */
class Specialty
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=255)
     */
    private $name;

    /**
     * @ORM\ManyToOne(targetEntity="App\Entity\Icon")
     */
    private $icon;

    /**
     * @ORM\Column(type="boolean")
     */
    private $status;

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

    public function setId($id)
    {
        $this->id = $id;
    }

    /**
     * Get string
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Set name
     * @param string $name
     * @return Specialty
     */
    public function setName($name)
    {
        $this->name = $name;
        return $this;
    }

    /**
     * @return mixed
     */
    public function getIcon()
    {
        return $this->icon;
    }

    /**
     * @param mixed $icon
     * @return $this
     */
    public function setIcon($icon)
    {
        $this->icon = $icon;

        return $this;
    }

    public function getStatus()
    {
        return $this->status;
    }

    public function setStatus($status)
    {
        $this->status = $status;
        return $this;
    }

    public function __toString()
    {
        return $this->getId() ? (string) $this->getName() : '-';
    }
}

1 Ответ

0 голосов
/ 22 мая 2019

Запустили ли вы php bin/console make:migration после настройки сущности?

  • php bin / console make: entity (создайте или обновите сущность)
  • Если вы предпочитаете добавлять новые свойствавручную команда make: entity может сгенерировать для вас методы получения и установки: php bin / console make: entity --regenerate
  • php bin / console make: миграция
  • inspect src/Migrations/папка
  • запуск миграций php bin/console doctrine:migrations:migrate

чтение

...