Skip to content

Instantly share code, notes, and snippets.

@codecowboy
Created September 1, 2011 09:49
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 codecowboy/1185843 to your computer and use it in GitHub Desktop.
Save codecowboy/1185843 to your computer and use it in GitHub Desktop.
Motivation repository
<?php
namespace Gymloop\CoreBundle\Entity;
use Doctrine\ORM\EntityRepository;
/**
* MotivationRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class MotivationRepository extends EntityRepository
{
public function findOneOrderedByDate($user)
{
$query = $this->getEntityManager()->createQuery('
SELECT m FROM GymloopCoreBundle:Motivation m
WHERE m.user = :user
ORDER BY m.date DESC');
$query->setParameter('user',$user);
$query->setFirstResult(0);
$query->setMaxResults(1);
//@TODO if there is not result recorded for the user, return sth which indicates this
return $query->getResult();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment