-1

I am trying call a function created function in Entity Repository

public function getBillGroupByDate($dateStart, $dateEnd) {
    return $query = $this->createQueryBuilder('d')
        ->select('count(d) as nb, SUBSTRING(d.created, 1, 10) as bill_date')
        ->having('DATE(bill_date) BETWEEN :from AND :to')
        ->groupBy('bill_date')
        ->orderBy('d.created', 'ASC')
        ->setParameter('from', $dateStart)
        ->setParameter('to', $dateEnd)
        ->getQuery()
        ->getResult();
}

I'm using a berberlei bundle who's have create most needed DQL function to doctrine. The function date seems well

<?php

namespace DoctrineExtensions\Query\Mysql;

use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\Lexer;

/**
 * @author Steve Lacey <steve@stevelacey.net>
 */
class Date extends FunctionNode
{
    public $date;

    public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
    {
        return 'DATE(' . $sqlWalker->walkArithmeticPrimary($this->date) . ')';
    }

    public function parse(\Doctrine\ORM\Query\Parser $parser)
    {
        $parser->match(Lexer::T_IDENTIFIER);
        $parser->match(Lexer::T_OPEN_PARENTHESIS);

        $this->date = $parser->ArithmeticPrimary();

        $parser->match(Lexer::T_CLOSE_PARENTHESIS);
    }
}

but for a reason that I do not know i have always an exception, maybe because the column name is an alias and not really exist ?

HTTP 500 Internal Server Error Notice: Undefined index: metadata Exception Symfony\Component\Debug\Exception\ ContextErrorException in vendor\doctrine\orm\lib\Doctrine\ORM\Query\SqlWalker.php (line 604) * * @return string */ public function walkEntityIdentificationVariable($identVariable) { $class = $this->queryComponents[$identVariable]['metadata']; $tableAlias = $this->getSQLTableAlias($class->getTableName(), $identVariable); $sqlParts = array(); foreach ($this->quoteStrategy->getIdentifierColumnNames($class, $this->platform) as $columnName) { $sqlParts[] = $tableAlias . '.' . $columnName;

1 Answers1

0

The issue is you can not use the DATE function from berberlei bundle since that function is expecting a column and you are passing the alias 'bill_date' which is an String. You can create your own function DATE to expect an String variable.

user3267053
  • 166
  • 7