我们正在使用Doctrine v2.2.1。使用YML定义的实体。Doctrine2两个实体的多重关系
这里我有两个实体,它们是指给定的关联彼此;
entities\User:
type: entity
table: user
oneToMany:
subjectNews:
targetEntity: entities\News
mappedBy: subjectUser
cascade: ["all"]
actionNews:
targetEntity: entities\News
mappedBy: actionUser
cascade: ["all"]
entities\News:
type: entity
table: news
manyToOne:
subjectUser:
targetEntity: entities\User
cascade: ["all"]
nullable: true
actionUser:
targetEntity: entities\User
cascade: ["all"]
nullable: true
当我根据这些定义生成实体类时,我在我的实体\ User php类中得到了意外的结果。这是什么样的;
/**
* Add subjectNews
*
* @param entities\News $subjectNews
* @return User
*/
public function addNews(\entities\News $subjectNews)
{
$this->subjectNews[] = $subjectNews;
return $this;
}
我的实体中的setter方法按预期生成的很好。但实体\用户的添加方法不会按预期方式生成。
我做错了什么?或者有什么解决方法呢?或者它与the issue referred in the Limitations and Known Issues doc of Doctrine2?
和平
结帐[这个答案] [1] [1]:HTTP ://stackoverflow.com/questions/6299738/doctrine-symfony-multiple-one-to-many-relations-on-same-model – frail 2012-04-17 18:01:53