Skip to content

bugfix - add fieldAlias for entities in dto#12236

Merged
greg0ire merged 1 commit intodoctrine:3.5.xfrom
eltharin:bugfix_fieldalias_entityInDto
Oct 23, 2025
Merged

bugfix - add fieldAlias for entities in dto#12236
greg0ire merged 1 commit intodoctrine:3.5.xfrom
eltharin:bugfix_fieldalias_entityInDto

Conversation

@eltharin
Copy link
Copy Markdown
Contributor

@eltharin eltharin commented Oct 22, 2025

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?`

@eltharin eltharin force-pushed the bugfix_fieldalias_entityInDto branch 2 times, most recently from c9fee49 to 1303578 Compare October 22, 2025 12:44
@eltharin eltharin force-pushed the bugfix_fieldalias_entityInDto branch from 1303578 to f71aa73 Compare October 22, 2025 19:14
@greg0ire greg0ire added this to the 3.5.3 milestone Oct 23, 2025
@greg0ire greg0ire merged commit 4f36f01 into doctrine:3.5.x Oct 23, 2025
107 of 108 checks passed
@greg0ire
Copy link
Copy Markdown
Member

Thanks @eltharin

@eltharin eltharin deleted the bugfix_fieldalias_entityInDto branch October 24, 2025 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants