我有一个连接到数据库的 Symfony2 项目。对于每个表,我都有一个实体。
现在,我正在尝试使用 ManyToOne 将一个实体与另一个实体连接起来。
问题是:
我有两个实体:用户和工作场所。
在用户实体中,我有:
/**
* @ORM\ManyToOne(targetEntity="Workplace")
* @ORM\JoinColumn(name="workplace", referencedColumnName="place")
**/
protected $workplace;
/**
* Set workplace
*
* @param integer $workplace
*/
public function setWorkplace($workplace)
{
$this->workplace = $workplace;
}
/**
* Get workplace
*
* @return integer
*/
public function getWorkplace()
{
return $this->workplace;
}
在我的工作场所实体中:
/**
* @ORM\Column(type="text")
*/
protected $place;
/**
* Set place
*
* @param text $place
*/
public function setPlace($place)
{
$this->place = $place;
}
/**
* Get place
*
* @return text
*/
public function getPlace()
{
return $this->place;
}
有了这个,我得到了一个异常(exception):
Neither property "workplace" nor method "getWorkplace()" nor method "isWorkplace()" exists in class "SciForum\Version2Bundle\Entity\Workplace"
如何解决这个问题。非常感谢。
最佳答案
试试这个
->add('place','entity', array('class'=>'yourBundle:WorkPlace',
'property'=>'place'))
在您的表单类型中。
关于database - Symfony2 : Database and Entity settings: Neither property . .. 类中也没有方法 ... 也没有方法 ... 存在于类中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12853731/