I have the fields firstname
and lastname
in my MySQL table. For convenience, I want to add a computed column to my Doctrine 2 entity called full_name
. In plain old MySQL I would do something like this
SELECT CONCAT(firstname, " ", lastname) AS full_name FROM customers;
However, concatenating fields and constant strings (" " in this case) seems not to work with Doctrine's implementation of CONCAT. When using the following code
$repository
->createQueryBuilder('customer')
->select('CONCAT(customer.firstname, " ", customer.lastname) AS full_name')
// ...
I get the error
[Syntax Error] line 0, col 91: Error: Expected StateFieldPathExpression | string | InputParameter | FunctionsReturningStrings | AggregateExpression, got '"'
How can I achieve the same behavior as in MySQL?