Why I cannot retrieve computed fields along with collections? #5412

Closed
opened 2026-01-22 15:07:05 +01:00 by admin · 1 comment
Owner

Originally created by @JCMais on GitHub (Feb 7, 2017).

Say I have 2 entities, Product and Tag, where Product has an one-to-many relationship with Tag.

Using the array hydration mode, this query correctly returns the product fields with all tags (as one array):

SELECT p as product, tags FROM app:Product p LEFT JOIN p.tags tags
[
    'product' => [
        'name' => 'Product #1',
        'tags'   => [
            [
                'name' => 'tag-1'
            ],
            [
                'name' => 'tag-2'
            ]
        ]
    ]
]

But this returns one single tag in the array:

SELECT p as product, tags, SUM( 0 ) as computedValue FROM app:Product p LEFT JOIN p.tags tags
    'product' => [
        'name' => 'Product #1',
        'tags'   => [
            [
                'name' => 'tag-1'
            ]
        ],
    ],
    'computedValue' => '0'
]

Why is that?

Using PHP 7 and "doctrine/orm": "~2.5.5",

Originally created by @JCMais on GitHub (Feb 7, 2017). Say I have 2 entities, ``Product`` and ``Tag``, where ``Product`` has an one-to-many relationship with ``Tag``. Using the array hydration mode, this query correctly returns the product fields with all tags (as one array): ``` SELECT p as product, tags FROM app:Product p LEFT JOIN p.tags tags ``` ``` [ 'product' => [ 'name' => 'Product #1', 'tags' => [ [ 'name' => 'tag-1' ], [ 'name' => 'tag-2' ] ] ] ] ``` But this returns one single tag in the array: ``` SELECT p as product, tags, SUM( 0 ) as computedValue FROM app:Product p LEFT JOIN p.tags tags ``` ``` 'product' => [ 'name' => 'Product #1', 'tags' => [ [ 'name' => 'tag-1' ] ], ], 'computedValue' => '0' ] ``` Why is that? Using PHP 7 and "doctrine/orm": "~2.5.5",
admin closed this issue 2026-01-22 15:07:06 +01:00
Author
Owner

@JCMais commented on GitHub (Feb 8, 2017):

I'm so dumb. To get the expected result, it's needed to group by product.id and tags.id.

@JCMais commented on GitHub (Feb 8, 2017): I'm so dumb. To get the expected result, it's needed to group by ``product.id`` and ``tags.id``.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5412