Skip to content

Commit 7f9b835

Browse files
authored
Add #[QueryResultDocument] to the attributes reference (#2907)
1 parent 5e230a5 commit 7f9b835

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

docs/en/reference/aggregation-builder.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ single result or return an iterator containing all results.
112112
If you instead want to look at the built aggregation pipeline, call the
113113
``Builder::getPipeline()`` method.
114114

115+
.. _aggregation_builder_hydration:
116+
115117
Hydration
116118
---------
117119

docs/en/reference/attributes-reference.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,45 @@ the method to be registered.
983983
984984
See :ref:`lifecycle_events` for more information.
985985

986+
#[QueryResultDocument]
987+
----------------------
988+
989+
Marks the document as query result document used when hydrating the aggregation query results.
990+
These documents can use all features regular documents can use but they will not be persisted to the database.
991+
992+
.. code-block:: php
993+
994+
<?php
995+
996+
#[QueryResultDocument]
997+
class CompanyTransactions
998+
{
999+
#[ReferenceOne(targetDocument=Company::class, name="_id")]
1000+
private string $company;
1001+
1002+
#[Field]
1003+
private float $totalAmount;
1004+
}
1005+
1006+
Use the ``hydrate()`` method of the Aggregation Builder to specify the class
1007+
to use for hydration.
1008+
1009+
.. code-block:: php
1010+
1011+
<?php
1012+
1013+
$builder = $dm->createAggregationBuilder(Transaction::class);
1014+
$builder
1015+
->hydrate(CompanyTransactions::class)
1016+
->group()
1017+
->field('_id')
1018+
->expression('$company')
1019+
->field('totalAmount')
1020+
->sum('$amount');
1021+
1022+
1023+
See :ref:`aggregation_builder_hydration` for more information.
1024+
9861025
#[ReadPreference]
9871026
-----------------
9881027

0 commit comments

Comments
 (0)