Php MongoDB,条令2&;举一反三
是关于同一个表中一对多的关联,但在MongoDB中Php MongoDB,条令2&;举一反三,php,mongodb,reference,doctrine,one-to-many,Php,Mongodb,Reference,Doctrine,One To Many,是关于同一个表中一对多的关联,但在MongoDB中 class Component { ... /** * @MongoDB\ReferenceMany( * discriminatorMap={ * "component"="Component" * }, * inversedBy="components.id", * cascade={"persist", "remove", "refres
class Component
{
...
/**
* @MongoDB\ReferenceMany(
* discriminatorMap={
* "component"="Component"
* },
* inversedBy="components.id",
* cascade={"persist", "remove", "refresh", "merge"}
* )
*
*/
protected $components;
public function __construct()
{
$this->components = new ArrayCollection();
}
/**
* Add components
*
* @param $component
*/
public function addComponents(Component $component)
{
if(!$this->components->contains($component)){
$this->components->add($component);
}
}
...
}
这会将组件关联到我没有问题,我查看集合并实际关联到我,但是当我尝试重新获得组件时,$This->components不是ArrayCollection,而是对象组件
有什么想法吗?已经解决了
/**
* @MongoDB\ReferenceOne(targetDocument="Component", inversedBy="children", cascade={"all"})
*/
public $parent;
/**
* @MongoDB\ReferenceMany(targetDocument="Component", mappedBy="parent", cascade={"all"})
*/
public $children;
public function __construct()
{
$this->children = new \Doctrine\Common\Collections\ArrayCollection();
}
public function addChild(component $child)
{
if(!$this->children->contains($child)){
$child->parent = $this;
$this->children->add($child);
}
}
/**
* Get children
*
* @return Doctrine\Common\Collections\ArrayCollection $children
*/
public function getComponents()
{
return $this->children;
}