Skip to content

Instantly share code, notes, and snippets.

@Chrysweel
Last active December 18, 2015 03:48
Show Gist options
  • Save Chrysweel/5720254 to your computer and use it in GitHub Desktop.
Save Chrysweel/5720254 to your computer and use it in GitHub Desktop.
Relation Many to Many, Artist - Event. One artist can to be a lot of events, and Event can to have a lot of artist.
I want to recuperate events of one artist.
My entity event:
/**
* @ORM\ManyToMany(targetEntity="myproject\ArtisaBundle\Entity\Artist", inversedBy="events")
* @ORM\JoinTable(name="events_artists")
**/
protected $artists;
public function setArtists($artists){
$this->artists = $artists;
}
public function addArtists(\myproject\ArtistBundle\Entity\Artist $artist)
{
$this->artists[] = $artist;
}
public function getArtists(){
return $this->artists;
}
public function __construct() {
$this->artists = new \Doctrine\Common\Collections\ArrayCollection();
}
My entity artist:
/**
* @ORM\ManyToMany(targetEntity="myproject\MyBundle\Entity\Event", mappedBy="artists")
*/
protected $events;
public function __construct() {
$this->events = new \Doctrine\Common\Collections\ArrayCollection();
}
Now I want to from my repository, recuperate , the events of artist.
How could I do it ?
@Chrysweel
Copy link
Author

Before with a relation onetomany I can to do:

$queryEventsArtist = $em->createQuery('SELECT e FROM myproject\MyBundle\Entity\Event e WHERE e.artists=:artist AND ( e.dateFin >= :fecha OR e.date >= :fecha) ORDER BY e.date ASC');
        $queryEventsArtist->setParameters(array(
                'artist' => $a->getId(),
                'fecha' => new \DateTime('today')));
 $eventos = $queryEventosArtista->getResult();

But now ??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment