Skip to content

Instantly share code, notes, and snippets.

@mathiasverraes
Created March 23, 2011 10:16
Show Gist options
  • Save mathiasverraes/882898 to your computer and use it in GitHub Desktop.
Save mathiasverraes/882898 to your computer and use it in GitHub Desktop.
<?php
/** @Entity */
class Bug
{
/** @Column(type="integer") */
private $id;
/** @Column(length=50) */
private $status;
//...
}
<?php
// $em instanceof Doctrine\ORM\EntityManager
$fixedbugs = $em->getRepository('Bug')
->findBy(array('status' => 'fixed'));
<?php
$fixedbugs = $em
->createQuery("SELECT b FROM Bug b WHERE b.status = 'fixed'")
->getResult();
<?php
/**
* @Entity(repositoryClass="BugRepository")
*/
class Bug
{ /* ... */ }
class BugRepository extends EntityRepository
{
public function findAllFixedBugs()
{
return $this->_em
->createQuery("SELECT b FROM Bug b WHERE b.status = 'fixed'")
->getResult();
}
}
<?php
$fixedbugs = $em->getRepository('Bug')->findAllFixedBugs();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment