我在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中实现相同的行为?