[PR #12236] [MERGED] bugfix - add fieldAlias for entities in dto #13603

Open
opened 2026-01-22 16:17:45 +01:00 by admin · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/doctrine/orm/pull/12236
Author: @eltharin
Created: 10/22/2025
Status: Merged
Merged: 10/23/2025
Merged by: @greg0ire

Base: 3.5.xHead: bugfix_fieldalias_entityInDto


📝 Commits (1)

  • f71aa73 bugfix - add fieldAlias for entities in dto

📊 Changes

5 files changed (+176 additions, -5 deletions)

View changed files

📝 src/Query/AST/EntityAsDtoArgumentExpression.php (+4 -0)
📝 src/Query/Parser.php (+2 -1)
📝 tests/Tests/Models/CMS/CmsUserDTONamedArgs.php (+2 -0)
📝 tests/Tests/Models/CMS/CmsUserDTOVariadicArg.php (+6 -4)
📝 tests/Tests/ORM/Functional/NewOperatorTest.php (+162 -0)

📄 Description

from slack :

Hello, I'm playing with Doctrine ORM 3.5 and trying to use the SELECT NEW NAMED syntax to hydrate a DTO. I have a question about passing complete entity objects as constructor parameters; This works fine

$qb->select(sprintf('NEW %s(
    p.id,
    p.name,
    p.level,
    ...,
    t,           // Type entity works
    p.nickname
)', PokemonDetailView::class))
->leftJoin('p.type', 't')

But this doesn't

// Attempt 1: without AS
'NEW NAMED %s(..., t, ...)' 
// Error: Column name "t" does not match any property name

// Attempt 2: with AS
'NEW NAMED %s(..., t AS type, ...)'
// Error: Column name "t AS type" does not match any property name

// Attempt 3: only entity without AS, scalars with AS
'NEW NAMED %s(
    p.id AS id,
    p.name AS name,
    t,              // Entity without AS
    p.nickname AS nickname
)'
// Error: Column name "t" does not match any property name

According to the documentation, "you can only pass scalar expressions or other Data Transfer Objects to the constructor." However, I'm able to pass entity objects successfully with positional SELECT NEW. Is this limitation also applicable to SELECT NEW NAMED, or is there a specific syntax I'm missing for passing entity objects with named parameters?`


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/doctrine/orm/pull/12236 **Author:** [@eltharin](https://github.com/eltharin) **Created:** 10/22/2025 **Status:** ✅ Merged **Merged:** 10/23/2025 **Merged by:** [@greg0ire](https://github.com/greg0ire) **Base:** `3.5.x` ← **Head:** `bugfix_fieldalias_entityInDto` --- ### 📝 Commits (1) - [`f71aa73`](https://github.com/doctrine/orm/commit/f71aa73ef144d573e7ceb573dffeeabc86317a8b) bugfix - add fieldAlias for entities in dto ### 📊 Changes **5 files changed** (+176 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `src/Query/AST/EntityAsDtoArgumentExpression.php` (+4 -0) 📝 `src/Query/Parser.php` (+2 -1) 📝 `tests/Tests/Models/CMS/CmsUserDTONamedArgs.php` (+2 -0) 📝 `tests/Tests/Models/CMS/CmsUserDTOVariadicArg.php` (+6 -4) 📝 `tests/Tests/ORM/Functional/NewOperatorTest.php` (+162 -0) </details> ### 📄 Description from slack : > Hello, I'm playing with Doctrine ORM 3.5 and trying to use the SELECT NEW NAMED syntax to hydrate a DTO. I have a question about passing complete entity objects as constructor parameters; This works fine ```php $qb->select(sprintf('NEW %s( p.id, p.name, p.level, ..., t, // Type entity works p.nickname )', PokemonDetailView::class)) ->leftJoin('p.type', 't') ``` > But this doesn't ``` // Attempt 1: without AS 'NEW NAMED %s(..., t, ...)' // Error: Column name "t" does not match any property name // Attempt 2: with AS 'NEW NAMED %s(..., t AS type, ...)' // Error: Column name "t AS type" does not match any property name // Attempt 3: only entity without AS, scalars with AS 'NEW NAMED %s( p.id AS id, p.name AS name, t, // Entity without AS p.nickname AS nickname )' // Error: Column name "t" does not match any property name ``` > According to the [documentation](https://www.doctrine-project.org/projects/doctrine-orm/en/3.5/reference/dql-doctrine-query-language.html#new-operator-syntax), "you can only pass scalar expressions or other Data Transfer Objects to the constructor." However, I'm able to pass entity objects successfully with positional SELECT NEW. Is this limitation also applicable to SELECT NEW NAMED, or is there a specific syntax I'm missing for passing entity objects with named parameters?` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
admin added the pull-request label 2026-01-22 16:17:45 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#13603