我有一个实体,我想使用特征“TimestampableEntity”来映射一些属性:
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;
这是我的时间戳实体特征:
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;
}
}
当我在我的实体上运行< code > PHP bin/console doctrine:generate:entities Wbudowie \ portal bundle 时,添加了以下代码:
/**
* @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\Entity\Category和Wbudovie\PortalBundle\Traits\TimestampbleEntity在Wbudowei\PortalBundle \Entity\Catagory的组成中定义了相同的属性($createdAt)。这可能是不兼容的,为了提高可维护性,请考虑在traits中使用访问器方法。类由/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
我在这方面取得了成功。请尝试以下步骤:
首先将实体注释添加到特征中:
/**
* @ORM\Entity
*/
trait TimestampableEntity
临时将其更改为类
/**
* @ORM\Entity
*/
class TimestampableEntity
运行生成:实体
对您的trait:
app/console doctrine:generate:entities WbudowiePortalBundle:Traits/TimestampableEntity
将时间戳实体
更改回特征:
/**
* @ORM\Entity
*/
trait TimestampableEntity
将特征添加到类别
class Category {
use TimestampableEntity;
如果您现在使用:
app/console doctrine:generate:entities WbudowiePortalBundle:Category
您不应看到重复项。我不确定,但我相信这是有效的,因为您的特征的获取者和二传手现在将与可能在类别
中创建的相同,因此它们不会被替换。手动编码 getter 和设置可能会导致差异,导致 Doctrine 认为类别中需要
新代码。
这里
这就是实现目标可能需要的全部内容。
据此,这是你无能为力的事情。只是不要使用生成实体:)
我正在构建React 16.13应用程序。我想从我的状态复制一个属性,以便对其进行操作并保持基础状态不变。我以为这就是解决问题的方法。。。 但是这条线 给出错误 按值复制状态变量的正确方法是什么?
本文向大家介绍在MongoDB中如何复制属性?,包括了在MongoDB中如何复制属性?的使用技巧和注意事项,需要的朋友参考一下 要将一个属性的值复制到另一个属性,请使用$set和update()。让我们创建一个包含文档的集合 在find方法的帮助下显示集合中的所有文档- 这将产生以下输出- 以下是在MongoDB中复制属性的查询- 在find方法的帮助下显示集合中的所有文档- 这将产生以下输出-
表单(form)以及例如 <input> 的控件(control)元素有许多特殊的属性和事件。 当我们学习了这些相关内容后,处理表单会变得更加方便。 导航:表单和元素 文档中的表单是特殊集合 document.forms 的成员。 这就是所谓的“命名的集合”:既是被命名了的,也是有序的。我们既可以使用名字,也可以使用在文档中的编号来获取表单。 document.forms.my - name="m
本文向大家介绍说说Context有哪些属性?相关面试题,主要包含被问及说说Context有哪些属性?时的应答技巧和注意事项,需要的朋友参考一下 简单介绍下Context: 提供了一个无需为每层组件手动添加 ,就能在组件树间进行数据传递的方法。我们在平时开发中如果不使用redux 这种数据状态管理库,可能在数据传递的时候使用的就是从祖先元素层层传递的方式,当层级较多之后,我们需要将数据通过组件的pr
属性与Java中的字段是相同的,但是更加强大。属性做的事情是字段加上getter加上setter。我们通过一个例子来比较他们的不同之处。这是Java中字段安全访问和修改所需要的代码: public class Person { private String name; public String getName() { return name; }
本文向大家介绍jQuery学习笔记之jQuery原型属性和方法,包括了jQuery学习笔记之jQuery原型属性和方法的使用技巧和注意事项,需要的朋友参考一下 以上就是该版本的jQuery的原型上的部分属性和方法. selector:用于记录init参数的selector.但不一定是相等的. $("div").selector;//"div" $("div").find(p).selecctor;