lunes, 6 de agosto de 2012

Doctrine2 y Symfony2 - DQL

Alta de registro simple

$em = $this->getDoctrine()->getEntityManager();
$aereoReserva = new AereoReserva();
$aereoReserva->setCodigoAmadeus('asdf');
$aereoReserva->setCodigoAerolinea('asdfsadf'); 
$em->persist($aereoReserva);
$em->flush();

Consulta simple con DQL

$em = $this->getDoctrine()->getEntityManager();
$query = $em->createQuery("SELECT CONCAT(a.aerolinea, CONCAT(' (', CONCAT(a.iata,')')))  AS label, a.iata AS value FROM AereoBundle:Aerolineas a WHERE a.aerolinea LIKE :aerolinea ")->setParameter('aerolinea', "%$searchterm%");
$entities = $query->getResult();

No hay comentarios:

Publicar un comentario