symfony - GroupBy DAY using Doctrine2 -


i looking way group policies day. trying lot of examples how still there errors. can me this? here show 2 examples, others trying similar those. differences in used sql's functions ex(cast, substring, date...) first way trying is:

$query =  $this->getentitymanager()                         ->createquerybuilder();    $query->select('count(p), p.transactiondate')                         ->from('glpolicybundle:policy', 'p')                         ->andwhere('p.shop in (:shop_id)')                         ->setparameter('shop_id', $shop_list)                         ->andwhere($query->expr()->between('p.transactiondate', ':date_from', ':date_to'))                         ->setparameter('date_from', $date_from, \doctrine\dbal\types\type::datetime)                         ->setparameter('date_to', $date_to, \doctrine\dbal\types\type::datetime)                         ->addgroupby('day(p.transactiondate)'); 

getdql() returns:

select count(p), p.transactiondate glpolicybundle:policy p  p.shop in (:shop_id) , (p.transactiondate between :date_from , :date_to)  group day(p.transactiondate) 

and error is:

[semantical error] line 0, col 156 near 'day(p.transa': error: cannot group undefined identification or result variable.

and second way is:

$query = $this->getentitymanager()             ->createquery("select p,  (p.transactiondate) group                             glpolicybundle:policy p                             p.shop in (:shop_id) , (p.transactiondate between :date_from , :date_to)                              group day(group)")                             ->setparameter('shop_id', $shop_list)                             ->setparameter('date_from', $date_from, \doctrine\dbal\types\type::datetime)                             ->setparameter('date_to', $date_to, \doctrine\dbal\types\type::datetime); 

getdql() returns:

select p, (p.transactiondate) group glpolicybundle:policy p  p.shop in (:shop_id) , (p.transactiondate between :date_from , :date_to)  group day(group) 

and error is:

[semantical error] line 0, col 72 near 'from glpolicybundle:policy': error: class 'from' not defined.

doctrine doesn't support many of native db functions because supposed work many different types of databases. you're left 3 options.

  1. use nativequery class (http://docs.doctrine-project.org/en/latest/reference/native-sql.html)
  2. implement custom sql walker. here example grouping day (https://github.com/beberlei/doctrineextensions/blob/master/lib/doctrineextensions/query/mysql/day.php)
  3. install bundle adds grouping methods https://github.com/beberlei/doctrineextensions

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -