Created
March 16, 2012 16:48
-
-
Save tobiassjosten/2051055 to your computer and use it in GitHub Desktop.
Doctrine2 m2m
This file contains 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 Smartburk\Bundle\MainBundle\Entity; | |
use Doctrine\ORM\Mapping as ORM; | |
/** | |
* @ORM\Entity( | |
* repositoryClass="Smartburk\Bundle\MainBundle\Entity\SeriesRepository" | |
* ) | |
* @ORM\Table(name="series") | |
*/ | |
class Series | |
{ | |
// ... | |
/** | |
* @ORM\ManyToMany( | |
* targetEntity="Smartburk\Bundle\MainBundle\Entity\Series", | |
* inversedBy="followers" | |
* ) | |
* @ORM\JoinTable(name="user_following") | |
*/ | |
protected $following; | |
/** | |
* Add following | |
* | |
* @param Smartburk\Bundle\MainBundle\Entity\Series $following | |
*/ | |
public function addFollowing(\Smartburk\Bundle\MainBundle\Entity\Series $following) | |
{ | |
$this->following[] = $following; | |
} | |
/** | |
* Get following | |
* | |
* @return Doctrine\Common\Collections\Collection | |
*/ | |
public function getFollowing() | |
{ | |
return $this->following; | |
} | |
// ... | |
} |
This file contains 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 Smartburk\Bundle\MainBundle\Entity; | |
use Doctrine\ORM\Mapping as ORM; | |
use FOS\UserBundle\Entity\User as BaseUser; | |
/** | |
* @ORM\Entity | |
* @ORM\Table(name="fos_user") | |
*/ | |
class User extends BaseUser | |
{ | |
// ... | |
/** | |
* @ORM\ManyToMany( | |
* targetEntity="Smartburk\Bundle\MainBundle\Entity\Series", | |
* inversedBy="followers" | |
* ) | |
* @ORM\JoinTable(name="user_following") | |
*/ | |
protected $following; | |
/** | |
* Add following | |
* | |
* @param Smartburk\Bundle\MainBundle\Entity\Series $following | |
*/ | |
public function addFollowing(\Smartburk\Bundle\MainBundle\Entity\Series $following) | |
{ | |
$this->following[] = $following; | |
} | |
/** | |
* Get following | |
* | |
* @return Doctrine\Common\Collections\Collection | |
*/ | |
public function getFollowing() | |
{ | |
return $this->following; | |
} | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment