[英]Add fields for Sonata UserBundle
I have a question about extending Sonata UserBundle entity. 我有关于扩展Sonata UserBundle实体的问题。 I need to add more fields to the entity.
我需要向实体添加更多字段。 Firstly, I extended Sonata UserBundle to my project on the folder src\\Application\\Sonata\\UserBundle Then I tried to add these fields on the User Entity available on the same folder:
首先,我将Sonata UserBundle扩展到文件夹src \\ Application \\ Sonata \\ UserBundle上的项目然后我尝试在同一文件夹上可用的用户实体上添加这些字段:
<?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;
}
}
On the fos_user.yml I mapped this entity. 在fos_user.yml上我映射了这个实体。 But when I try to update my schema, by running this command:
但是当我尝试通过运行此命令来更新我的架构时:
php bin/console doctrine:s:u --force
I have a message that states that Nothing to update - your database is already in sync with the current entity metadata. 我有一条消息说明无需更新 - 您的数据库已与当前实体元数据同步。
The added field isn't added on my table. 添加的字段未添加到我的表格中。 I'm not an expert on Symfony, so I tried to explain my situation as possible as I can.
我不是Symfony的专家,所以我试着尽可能地解释我的情况。
Specialty entity: 专业实体:
<?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() : '-';
}
}
Did you run php bin/console make:migration
after adjusting the Entity? 调整实体后,您是否运行了
php bin/console make:migration
?
src/Migrations/
folder src/Migrations/
文件夹 php bin/console doctrine:migrations:migrate
php bin/console doctrine:migrations:migrate
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.