Created
June 4, 2013 12:06
-
-
Save dominikzogg/5705446 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Vendor\Bundle\Entity; | |
use Doctrine\Common\Collections\ArrayCollection; | |
use Doctrine\ORM\Mapping as ORM; | |
/** | |
* @ORM\Table(name="many_a") | |
* @ORM\Entity | |
*/ | |
class ManyA | |
{ | |
/** | |
* @var ManyB[] | |
* @ORM\ManyToMany(targetEntity="ManyB", mappedBy="maniesA") | |
*/ | |
protected $maniesB; | |
public function __construct() | |
{ | |
$this->maniesB = new ArrayCollection(); | |
} | |
/** | |
* @param ManyB $manyB | |
* @param bool $stopPropagation | |
* @return $this | |
*/ | |
public function addManyB(ManyB $manyB, $stopPropagation = false) | |
{ | |
$this->maniesB->add($manyB); | |
if(!$stopPropagation) { | |
$manyB->addManyA($this, true); | |
} | |
return $this; | |
} | |
/** | |
* @param ManyB $manyB | |
* @param bool $stopPropagation | |
* @return $this | |
*/ | |
public function removeManyB(ManyB $manyB, $stopPropagation = false) | |
{ | |
$this->maniesB->removeElement($manyB); | |
if(!$stopPropagation) { | |
$manyB->removeManyA($this, true); | |
} | |
return $this; | |
} | |
/** | |
* @param ManyB[] $maniesB | |
* @return $this | |
*/ | |
public function setManiesB($maniesB) | |
{ | |
foreach($this->maniesB as $manyB) { | |
$this->removeManyB($manyB); | |
} | |
foreach($maniesB as $manyB) { | |
$this->addManyB($manyB); | |
} | |
return $this; | |
} | |
/** | |
* @return ManyB[] | |
*/ | |
public function getManiesB() | |
{ | |
return $this->maniesB; | |
} | |
} | |
/** | |
* @ORM\Table(name="many_b") | |
* @ORM\Entity | |
*/ | |
class ManyB | |
{ | |
/** | |
* @var ManyA[] | |
* @ORM\ManyToMany(targetEntity="ManyA", inversedBy="maniesB") | |
* @ORM\JoinTable(name="manies_a_to_manies_b") | |
*/ | |
protected $maniesA; | |
public function __construct() | |
{ | |
$this->maniesA = new ArrayCollection(); | |
} | |
/** | |
* @param ManyA $manyA | |
* @param bool $stopPropagation | |
* @return $this | |
*/ | |
public function addManyA(ManyA $manyA, $stopPropagation = false) | |
{ | |
$this->maniesA->add($manyA); | |
if(!$stopPropagation) { | |
$manyA->addManyB($this, true); | |
} | |
return $this; | |
} | |
/** | |
* @param ManyA $manyA | |
* @param bool $stopPropagation | |
* @return $this | |
*/ | |
public function removeManyA(ManyA $manyA, $stopPropagation = false) | |
{ | |
$this->maniesA->removeElement($manyA); | |
if(!$stopPropagation) { | |
$manyA->removeManyB($this, true); | |
} | |
return $this; | |
} | |
/** | |
* @param ManyA[] $maniesA | |
* @return $this | |
*/ | |
public function setManiesA($maniesA) | |
{ | |
foreach($this->maniesA as $manyA) { | |
$this->removeManyA($manyA); | |
} | |
foreach($maniesA as $manyA) { | |
$this->addManyA($manyA); | |
} | |
return $this; | |
} | |
/** | |
* @return ManyA[] | |
*/ | |
public function getManiesA() | |
{ | |
return $this->maniesA; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment