Skip to content

Instantly share code, notes, and snippets.

@fprochazka
Created September 17, 2010 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fprochazka/584161 to your computer and use it in GitHub Desktop.
Save fprochazka/584161 to your computer and use it in GitHub Desktop.
<?php
// new movie
$movie = new Entities\Movie;
$movie->name = 'Pulp Fiction';
// new director
$movie->director = new Entities\Director;
$movie->director->name = 'Quentin Tarantino';
// existing genres
$qb = $this->entityManager->createQueryBuilder();
$tags = array('Crime', 'Thriller', 'Comedy', 'Drama');
$q = $qb->select('g')->from('Project\Entities\Genre', 'g');
if ($tags) {
$q->where($qb->expr()->in('g.name', $tags))
}
$movie->genres = $q->getQuery()->getResult();
$this->entityManager->beginTransaction();
$this->entityManager->persist($movie);
$this->entityManager->flush();
$this->entityManager->rollback();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment