doctrine-orm - 如何使用Doctrine连接select语句中的字段

标签 doctrine-orm

我想知道如何将 DQL select 语句中的两个字段与一些文字连接起来。

我现在有这个,但没有运气...

$qb
            ->select('season.id, concat(competition.name, '-',season.name) AS specs')
            ->leftJoin('season.competition', 'competition')
            ->where('season.name LIKE :q')
            ->setParameter('q', '%'.$q.'%')
            ->setMaxResults($p)
        ;

最佳答案

我们不能在这里发送三个参数,但我们可以这样做,

$em = \Zend_Registry::get('em');
        $qb_1 = $em->createQueryBuilder();
        $q_1 = $qb_1->select( "reprt_abs.id" )
        ->addSelect( "CONCAT( CONCAT(reporter.firstname, ' '),  reporter.lastname)" )
        ->from( '\Entities\report_abuse', 'reprt_abs' )
        ->leftJoin( 'reprt_abs.User', 'reporter' )
        ->getQuery()->getResult();

这部分是你想要的:

$qb_1->select( "reprt_abs.id" ) ->addSelect( "CONCAT( CONCAT(reporter.firstname, ' '), reporter.lastname)" )



以下是我这边的输出:
array (size=19)
  0 => 
    array (size=2)
      'id' => int 1
      1 => string 'Jaskaran Singh' (length=14)
  1 => 
    array (size=2)
      'id' => int 9
      1 => string 'Harsimer Kaur' (length=14)
  2 => 
    array (size=2)
      'id' => int 12
      1 => string 'Jaskaran Singh' (length=14)
  3 => 
    array (size=2)
      'id' => int 16
      1 => string 'Jaskaran Singh' (length=14)
  4 => 
    array (size=2)
      'id' => int 19
      1 => string 'Jaskaran Singh' (length=14)
  5 => 
    array (size=2)
      'id' => int 4
      1 => string 'shilpi jaiswal' (length=14)

关于doctrine-orm - 如何使用Doctrine连接select语句中的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28629100/

相关文章:

php - 教义一对多关系和多对一关系

symfony - 如何在 Doctrine 2 中配置命名策略

Symfony2 : class 'Doctrine\Common\Collections\ArrayCollection' was not found in the chain configured namespaces

php - Symfony2 实现数据库翻译的最佳方式

MySQL - 按非聚合列分组

php - 学说注释上的枚举类型问题

security - 实体提供程序 : No encoder has been configured for account

php - 动态目标实体 Doctrine 2 和 Symfony 2

repository - Symfony2 自定义存储库、延迟加载和代理对象

php - Doctrine2,传递 Id 还是对象?