0

同じテーブル内の1対多の関連付けに関するものですが、MongoDB内にあります。

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ではなく、オブジェクトコンポーネントになります。

何か案は?

4

1 に答える 1

0

解決しました...

/**
 * @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;
}
于 2013-02-04T11:53:09.700 に答える