【发布时间】:2016-04-15 09:44:08
【问题描述】:
我使用 Symfony 3 从现有项目开发 Web 应用程序已有 8 年多的时间了。 因此,我继承了现有模型。
有些实体有这个字段
/**
* @var integer
*
* @ORM\Column(name="FourID_Site", type="bigint", nullable=true)
*/
private $fouridSite;
还有一些人有
/**
* @var \FourListe
*
* @ORM\ManyToOne(targetEntity="FourListe")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="FourID_Site", referencedColumnName="FourID")
* })
*/
private $fouridSite;
我有一个在所有持久化和刷新原则方法之前调用的方法,用于自动更新某些字段。
if (property_exists(get_class($entity), 'fouridSite')) {
$entity->setFouridSite($this->current_user->getFouridSiteutilisateur());
}
if (property_exists(get_class($entity), 'majlogin')) {
$entity->setMajlogin($this->current_user->getLogin());
}
if (property_exists(get_class($entity), 'majdate')) {
$entity->setMajdate(new \DateTime());
}
问题:当 $fouridSite 是 integer 时,此代码会引发错误,因为我无法分配实体 ( $this->current_user->getFouridSiteutilisateur() 返回一个 FourListe 实体) 当学说需要一个整数时。而且很正常。
在这种情况下不能使用原生 php 方法 get type(),因为它返回 NULL。
那么,也许有一种方法可以通过注解来知道$fourisSite 是一个实体还是一个整数?
感谢您的想法或潜在的任何建议?
【问题讨论】:
标签: php symfony doctrine-orm annotations