Doctrine orm Doctrine2不能使';2';一对多关系
我试图用以下关系建立3个实体(项目、同意、不同意)Doctrine orm Doctrine2不能使';2';一对多关系,doctrine-orm,doctrine,yaml,one-to-many,Doctrine Orm,Doctrine,Yaml,One To Many,我试图用以下关系建立3个实体(项目、同意、不同意) 一对多同意 一对多不同意 但两个关系中只有一个(稍后声明)发生了错误 这是我的.yml文件 下面的代码是Doctrine2自动生成的Item.php。如您所见,它根本不包含“同意” 如果我切换声明顺序(“先是“不同意”,然后是“同意”,如下所示),Item.php此时只有与“同意”相关的代码 我的代码怎么了?任何意见都会有帮助 项目、同意和不同意只是显示此问题的示例。在实际项目中,同意和不同意是完全不同的实体。所以,不要建议
- 一对多同意
- 一对多不同意
下面的代码是Doctrine2自动生成的Item.php。如您所见,它根本不包含“同意”
如果我切换声明顺序(“先是“不同意”,然后是“同意”,如下所示),Item.php此时只有与“同意”相关的代码
我的代码怎么了?任何意见都会有帮助
项目、同意和不同意只是显示此问题的示例。在实际项目中,同意和不同意是完全不同的实体。所以,不要建议我将它们合并到统一实体中。:) 您很接近,只需将所有相同的关联映射类型放在相同的类型声明下:)
很接近,您只需要将所有相同的关联映射类型放在相同的类型声明下:)
Entities\Item:
type: entity
fields:
id:
type: integer
id: true
generator:
strategy: AUTO
oneToMany:
agrees:
targetEntity: Agree
mappedBy: items
oneToMany:
disagrees:
targetEntity: Disagree
mappedBy: items
Entities\Agree:
type: entity
fields:
id:
type: integer
id: true
generator:
strategy: AUTO
manyToOne:
items:
targetEntity: Item
inversedBy: agrees
Entities\Disagree:
type: entity
fields:
id:
type: integer
id: true
generator:
strategy: AUTO
manyToOne:
items:
targetEntity: Item
inversedBy: disagrees
namespace Entities;
class Item {
private $id;
private $disagrees;
public function __construct() {
$this->disagrees = new \Doctrine\Common\Collections\ArrayCollection();
}
public function getId() {
return $this->id;
}
public function addDisagrees(\Entities\Disagree $disagrees) {
$this->disagrees[] = $disagrees;
}
public function getDisagrees() {
return $this->disagrees;
}
}
Entities\Item:
type: entity
fields:
id:
type: integer
id: true
generator:
strategy: AUTO
oneToMany:
disagrees:
targetEntity: Disagree
mappedBy: items
oneToMany:
agrees:
targetEntity: Agree
mappedBy: items
oneToMany:
agrees:
targetEntity: Agree
mappedBy: items
disagrees:
targetEntity: Disagree
mappedBy: items