Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get the last element in doctrine2/symfony2

i have relation ManyToOne between two entity Collaborateur and Conge.

 /**
 * @ORM\ManyToOne(targetEntity="Collaborateur", inversedBy="collaborateur", cascade={"remove"})
 * @ORM\JoinColumn(name="collaborateur_id", referencedColumnName="id")
 */
protected $collaborateur;

In my CongeManager i have this function:

 public function findCongeByCollaborateur ($collaborateur){
        return $this->getRepository()->findOneBy(array('collaborateur'=>$collaborateur));
    }

it return just the first element of Conge i want to get the last one .

like image 627
lala Avatar asked Aug 18 '14 15:08

lala


1 Answers

$this->getRepository()->findOneBy(
         array('collaborateur'=>$collaborateur),
         array('id' => 'DESC')
);
like image 79
Omar Ghorbel Avatar answered Oct 04 '22 00:10

Omar Ghorbel