属性和方法,我有一个实体,在这里我想用特质“TimestampableEntity”映射某些属性:Doctrine2复制从特质
namespace Wbudowie\PortalBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Wbudowie\PortalBundle\Traits\TimestampableEntity;
/**
* Category
*
* @Gedmo\Tree(type="materializedPath")
* @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
* @ORM\Table(name="categories")
* @ORM\Entity(repositoryClass="CategoryRepository")
*/
class Category {
use TimestampableEntity;
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
这是我TimestampableEntity特点:
namespace Wbudowie\PortalBundle\Traits;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
trait TimestampableEntity {
/**
* @var \DateTime
*
* @Gedmo\Timestampable(on="create")
* @ORM\Column(name="created_at", type="datetime")
*/
private $createdAt;
/**
* @var \DateTime
*
* @Gedmo\Timestampable(on="update")
* @ORM\Column(name="edited_at", type="datetime", nullable=true)
*/
private $editedAt;
/**
* @var \DateTime
* @ORM\Column(name="deleted_at",type="datetime", nullable=true)
*/
private $deletedAt;
/**
* @var boolean
*
* @ORM\Column(name="is_active", type="boolean")
*/
private $isActive;
/**
* Sets createdAt.
*
* @param \DateTime $createdAt
* @return $this
*/
public function setCreatedAt(\DateTime $createdAt) {
$this->createdAt = $createdAt;
return $this;
}
/**
* Returns createdAt.
*
* @return \DateTime
*/
public function getCreatedAt() {
return $this->createdAt;
}
/**
* Sets updatedAt.
*
* @param \DateTime $updatedAt
* @return $this
*/
public function setUpdatedAt(\DateTime $updatedAt) {
$this->updatedAt = $updatedAt;
return $this;
}
/**
* Returns updatedAt.
*
* @return \DateTime
*/
public function getUpdatedAt() {
return $this->updatedAt;
}
/**
* Sets deletedAt.
*
* @param \Datetime|null $deletedAt
*
* @return $this
*/
public function setDeletedAt(\DateTime $deletedAt = null) {
$this->deletedAt = $deletedAt;
return $this;
}
/**
* Returns deletedAt.
*
* @return \DateTime
*/
public function getDeletedAt() {
return $this->deletedAt;
}
/**
* Is deleted?
*
* @return bool
*/
public function isDeleted() {
return null !== $this->deletedAt;
}
/**
* Set isActive
*
* @param boolean $isActive
* @return $this
*/
public function setIsActive($isActive) {
$this->isActive = $isActive;
return $this;
}
/**
* Get isActive
*
* @return boolean
*/
public function getIsActive() {
return $this->isActive;
}
}
当我在我的实体上运行php bin/console doctrine:generate:entities Wbudowie\PortalBundle
已在此实体中添加此代码:
/**
* @var \DateTime
*/
private $createdAt;
/**
* @var \DateTime
*/
private $editedAt;
/**
* @var \DateTime
*/
private $deletedAt;
/**
* @var boolean
*/
private $isActive;
/**
* Set createdAt
*
* @param \DateTime $createdAt
* @return Category
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
/**
* Get createdAt
*
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* Set editedAt
*
* @param \DateTime $editedAt
* @return Category
*/
public function setEditedAt($editedAt)
{
$this->editedAt = $editedAt;
return $this;
}
/**
* Get editedAt
*
* @return \DateTime
*/
public function getEditedAt()
{
return $this->editedAt;
}
/**
* Set deletedAt
*
* @param \DateTime $deletedAt
* @return Category
*/
public function setDeletedAt($deletedAt)
{
$this->deletedAt = $deletedAt;
return $this;
}
/**
* Get deletedAt
*
* @return \DateTime
*/
public function getDeletedAt()
{
return $this->deletedAt;
}
/**
* Set isActive
*
* @param boolean $isActive
* @return Category
*/
public function setIsActive($isActive)
{
$this->isActive = $isActive;
return $this;
}
/**
* Get isActive
*
* @return boolean
*/
public function getIsActive()
{
return $this->isActive;
}
之后,当我尝试做做任何事情,我得到这个错误,所以我必须删除生成的代码:
运行时注意事项:Wbudowie \ PortalBundle \实体\目录和Wbudowie \ PortalBundle \特征\ TimestampableEntity定义相同属性($ createdAt)在Wbudowie \ PortalBundle \ Entity \ Category的组合中。这可能是不兼容的,为了提高可维护性,请考虑在特征中使用访问器方法。类/mnt/DANE/projekty/wbudowie/src/Wbudowie/PortalBundle/Entity/Category.php线607
什么是错的组成?我使用PHP 5.5.9,学说2.4 *和Symfony的2.5 *
编辑:。 它,学说错误。它是固定的,但不在2.4.x版本中。
https://github.com/doctrine/doctrine2/pull/632
https://github.com/doctrine/doctrine2/pull/763
请写下你正在努力实现的目标 –
我不想复制从特质到实体的所有内容,因为我想让我的特质拥有一切。 – cyklista
当您使用特质时,此修补程序修复生成实体: http://pastebin.com/bQppqbg5 – cyklista