Ejemplos de consultas

 /**
     * @return Producto[] Returns an array of Producto objects
     */
    public function findByPrecioMayor($value) {
        return $this->createQueryBuilder('c')
                        ->andWhere('c.precio > :val')
                        ->setParameter('val', $value)
                        ->orderBy('c.id', 'ASC')
                        ->getQuery()
                        ->getResult()
        ;
    }

    /**
     * @return Producto[] Returns an array of Producto objects
     */
    public function findByNombre($value) {
        return $this->createQueryBuilder('c')
                        ->select('c.nombre')
                        ->where('c.nombre like :val')
                        ->setParameter('val', "%$value%")
                        ->orderBy('c.id', 'ASC')
                        ->getQuery()
                        ->getArrayResult()
        ;
    }

    /**
     * @return Producto[] Returns an array of Producto objects
     */
    public function countProductos() {
        return $this->createQueryBuilder('c')
                        ->select('count(c) as total')
                        ->getQuery()
                        ->getSingleScalarResult()
        ;
    }
  /**
     * @return Producto[] Returns an array of Producto objects
     */
    public function countProductosByTipo() {
        return $this->createQueryBuilder('c')
                        ->select('c.tipo, count(c) as total')
                ->groupBy('c.tipo')
                        ->getQuery()
                        ->getArrayResult()
        ;
    }

Publicado por

Avatar del usuario

Juan Pablo Fuentes

Formador de programación y bases de datos