{"id":181666,"date":"2013-05-31T15:50:03","date_gmt":"2013-05-31T11:50:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=181666"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=181666","title":{"rendered":"<span class=\"post_title\">\u041f\u043e\u043b\u043d\u0430\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 GROUP_CONCAT \u0432 Doctrine2<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u041f\u0440\u0438\u0432\u0435\u0442 \u0432\u0441\u0435\u043c.<\/p>\n<p>  \u0422\u0430\u043a \u0441\u043b\u043e\u0436\u0438\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435, \u043d\u0430\u0434 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u044f \u0441\u0435\u0439\u0447\u0430\u0441 \u0440\u0430\u0431\u043e\u0442\u0430\u044e, \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e GROUP_CONCAT(). \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, Doctrine2 \u00ab\u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438\u00bb \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442. <a href=\"https:\/\/github.com\/beberlei\/DoctrineExtensions\/blob\/master\/lib\/DoctrineExtensions\/Query\/Mysql\/GroupConcat.php\">\u0418\u043c\u0435\u044e\u0449\u0435\u0435\u0441\u044f \u0436\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u043e\u0442 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 (Benjamin Eberlei) Doctrine2 \u0437\u043d\u0430\u0447\u0438\u0442\u0441\u044f \u043a\u0430\u043a \u00ablimited support for GROUP_CONCAT\u00bb<\/a>. \u041f\u043e\u043d\u0438\u043c\u0430\u044e, \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u043e\u043c \u0441\u0442\u0430\u0432\u0438\u0442 \u043f\u0440\u043e\u0435\u043a\u0442 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043e\u0442 MySQL, \u043d\u043e \u043c\u0435\u043d\u044f\u0442\u044c \u0421\u0423\u0411\u0414 \u043a\u0430\u043a \u043f\u0435\u0440\u0447\u0430\u0442\u043a\u0438 \u043d\u0435 \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u0442\u0441\u044f. \u0422\u0430\u043a \u0447\u0442\u043e \u043e\u0441\u0442\u0430\u0432\u0438\u043c \u044d\u0442\u043e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u0437\u0430 \u0440\u0430\u043c\u043a\u0430\u043c\u0438 \u043f\u043e\u0441\u0442\u0430.<\/p>\n<p>  \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043f\u043e\u0433\u0443\u0433\u043b\u0438\u0432 \u044f \u043d\u0435 \u043d\u0430\u0448\u0435\u043b \u0433\u043e\u0442\u043e\u0432\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u0440\u0435\u0448\u0438\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0435\u0433\u043e \u0441\u0430\u043c (\u0432\u0437\u044f\u0432 \u0437\u0430 \u043e\u0441\u043d\u043e\u0432\u0443 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443 Benjamin&#8217;\u0430). \u041a\u043e\u043c\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043c \u043e\u0441\u043e\u0431\u043e \u043d\u0435\u0447\u0435\u0433\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e \u0435\u0433\u043e \u043d\u0430 \u0441\u0443\u0434 \u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u0438:<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<pre><code class=\"php\">\/**  * DoctrineExtensions Mysql Function Pack  *  * LICENSE  *  * This source file is subject to the new BSD license that is bundled  * with this package in the file LICENSE.txt.  * If you did not receive a copy of the license and are unable to  * obtain it through the world-wide-web, please send an email  * to kontakt@beberlei.de so I can send you a copy immediately.  *\/  namespace DoctrineExtensions\\Query\\Mysql;  use Doctrine\\ORM\\Query\\AST\\Functions\\FunctionNode,     Doctrine\\ORM\\Query\\Lexer;  \/**  * Full support for:  *   * GROUP_CONCAT([DISTINCT] expr [,expr ...]  *              [ORDER BY {unsigned_integer | col_name | expr}  *                  [ASC | DESC] [,col_name ...]]  *              [SEPARATOR str_val])  *   *\/ class GroupConcat extends FunctionNode {     public $isDistinct = false;     public $pathExp = null;     public $separator = null;     public $orderBy = null;      public function parse(\\Doctrine\\ORM\\Query\\Parser $parser)     {         $parser-&gt;match(Lexer::T_IDENTIFIER);         $parser-&gt;match(Lexer::T_OPEN_PARENTHESIS);                  $lexer = $parser-&gt;getLexer();         if ($lexer-&gt;isNextToken(Lexer::T_DISTINCT)) {             $parser-&gt;match(Lexer::T_DISTINCT);                          $this-&gt;isDistinct = true;         }          \/\/ first Path Expression is mandatory         $this-&gt;pathExp = array();         $this-&gt;pathExp[] = $parser-&gt;SingleValuedPathExpression();          while ($lexer-&gt;isNextToken(Lexer::T_COMMA)) {             $parser-&gt;match(Lexer::T_COMMA);             $this-&gt;pathExp[] = $parser-&gt;StringPrimary();         }          if ($lexer-&gt;isNextToken(Lexer::T_ORDER)) {             $this-&gt;orderBy = $parser-&gt;OrderByClause();         }                  if ($lexer-&gt;isNextToken(Lexer::T_IDENTIFIER)) {             if (strtolower($lexer-&gt;lookahead['value']) !== 'separator') {                 $parser-&gt;syntaxError('separator');             }             $parser-&gt;match(Lexer::T_IDENTIFIER);                      $this-&gt;separator = $parser-&gt;StringPrimary();         }          $parser-&gt;match(Lexer::T_CLOSE_PARENTHESIS);     }      public function getSql(\\Doctrine\\ORM\\Query\\SqlWalker $sqlWalker)     {         $result = 'GROUP_CONCAT(' . ($this-&gt;isDistinct ? 'DISTINCT ' : '');          $fields = array();         foreach ($this-&gt;pathExp as $pathExp) {             $fields[] = $pathExp-&gt;dispatch($sqlWalker);         }                  $result .= sprintf('%s', implode(', ', $fields));                  if ($this-&gt;orderBy) {             $result .= ' '.$sqlWalker-&gt;walkOrderByClause($this-&gt;orderBy);         }                  if ($this-&gt;separator) {             $result .= ' SEPARATOR '.$sqlWalker-&gt;walkStringPrimary($this-&gt;separator);         }                  $result .= ')';                  return $result;     }  } <\/code><\/pre>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"php\">$query = $this-&gt;createQueryBuilder('c')         -&gt;select(&quot;             c as company,             GroupConcat(b.id, ';', b.headOffice, ';', b.city, ';', s.name             ORDER by b.id             SEPARATOR '|') AS branches         &quot;)-&gt;leftJoin('c.branches','b')         -&gt;leftJoin('b.country','s')         -&gt;groupBy('c.id')         -&gt;setFirstResult(0)         -&gt;setMaxResults(10)         -&gt;getQuery() ; $result = $query-&gt;getResult() <\/code><\/pre>\n<p>  \u041e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u043f\u043e \u0442\u0435\u043c\u0435:<br \/>  <a href=\"http:\/\/docs.doctrine-project.org\/projects\/doctrine-orm\/en\/latest\/cookbook\/dql-user-defined-functions.html\">\u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 DQL \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432 Doctrine2<\/a><br \/>  <a href=\"http:\/\/symfony.com\/doc\/current\/cookbook\/doctrine\/custom_dql_functions.html\">\u041a\u0430\u043a \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 DQL \u0432 Symfony2<\/a>.<br \/>  <a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/group-by-functions.html#function_group-concat\">\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 MySQL-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 GROUP_CONCAT<\/a>    \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/181666\/\"> http:\/\/habrahabr.ru\/post\/181666\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u041f\u0440\u0438\u0432\u0435\u0442 \u0432\u0441\u0435\u043c.<\/p>\n<p>  \u0422\u0430\u043a \u0441\u043b\u043e\u0436\u0438\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435, \u043d\u0430\u0434 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u044f \u0441\u0435\u0439\u0447\u0430\u0441 \u0440\u0430\u0431\u043e\u0442\u0430\u044e, \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e GROUP_CONCAT(). \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, Doctrine2 \u00ab\u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438\u00bb \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442. <a href=\"https:\/\/github.com\/beberlei\/DoctrineExtensions\/blob\/master\/lib\/DoctrineExtensions\/Query\/Mysql\/GroupConcat.php\">\u0418\u043c\u0435\u044e\u0449\u0435\u0435\u0441\u044f \u0436\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u043e\u0442 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 (Benjamin Eberlei) Doctrine2 \u0437\u043d\u0430\u0447\u0438\u0442\u0441\u044f \u043a\u0430\u043a \u00ablimited support for GROUP_CONCAT\u00bb<\/a>. \u041f\u043e\u043d\u0438\u043c\u0430\u044e, \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u043e\u043c \u0441\u0442\u0430\u0432\u0438\u0442 \u043f\u0440\u043e\u0435\u043a\u0442 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043e\u0442 MySQL, \u043d\u043e \u043c\u0435\u043d\u044f\u0442\u044c \u0421\u0423\u0411\u0414 \u043a\u0430\u043a \u043f\u0435\u0440\u0447\u0430\u0442\u043a\u0438 \u043d\u0435 \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u0442\u0441\u044f. \u0422\u0430\u043a \u0447\u0442\u043e \u043e\u0441\u0442\u0430\u0432\u0438\u043c \u044d\u0442\u043e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u0437\u0430 \u0440\u0430\u043c\u043a\u0430\u043c\u0438 \u043f\u043e\u0441\u0442\u0430.<\/p>\n<p>  \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043f\u043e\u0433\u0443\u0433\u043b\u0438\u0432 \u044f \u043d\u0435 \u043d\u0430\u0448\u0435\u043b \u0433\u043e\u0442\u043e\u0432\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u0440\u0435\u0448\u0438\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0435\u0433\u043e \u0441\u0430\u043c (\u0432\u0437\u044f\u0432 \u0437\u0430 \u043e\u0441\u043d\u043e\u0432\u0443 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443 Benjamin&#8217;\u0430). \u041a\u043e\u043c\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043c \u043e\u0441\u043e\u0431\u043e \u043d\u0435\u0447\u0435\u0433\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e \u0435\u0433\u043e \u043d\u0430 \u0441\u0443\u0434 \u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u0438:  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-181666","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/181666","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=181666"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/181666\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=181666"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=181666"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=181666"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}