【发布时间】:2016-04-17 18:25:55
【问题描述】:
我的 MySQL 表中有 firstname 和 lastname 字段。为方便起见,我想在我的 Doctrine 2 实体中添加一个名为 full_name 的计算列。在普通的旧 MySQL 中,我会做这样的事情
SELECT CONCAT(firstname, " ", lastname) AS full_name FROM customers;
但是,连接字段和常量字符串(在本例中为“”)似乎不适用于 Doctrine 的 CONCAT 实现。使用以下代码时
$repository
->createQueryBuilder('customer')
->select('CONCAT(customer.firstname, " ", customer.lastname) AS full_name')
// ...
我得到了错误
[Syntax Error] line 0, col 91: Error: Expected StateFieldPathExpression | string | InputParameter | FunctionsReturningStrings | AggregateExpression, got '"'
如何实现与 MySQL 中相同的行为?
【问题讨论】:
标签: mysql string doctrine-orm concat