Skip to content

Commit

Permalink
Remove partial syntax in DQL
Browse files Browse the repository at this point in the history
It is no longer possible to use the "PARTIAL" keyword in a DQL query, or
to artificially build an AST with a partial object expression. It is
still possible to use the result set mapping API to build partial
objects.
  • Loading branch information
greg0ire committed Oct 10, 2023
1 parent 4799c41 commit 9e1946f
Show file tree
Hide file tree
Showing 24 changed files with 34 additions and 861 deletions.
7 changes: 7 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Upgrade to 3.0

## BC BREAK: Partial objects are removed

- The `PARTIAL` keyword no longer exists.
- `Doctrine\ORM\Query\AST\PartialObjectExpression`is removed.
- `Doctrine\ORM\Query\SqlWalker::HINT_PARTIAL` and
`Doctrine\ORM\Query::HINT_FORCE_PARTIAL_LOAD` are removed.

## BC BREAK: `Doctrine\ORM\Persister\Entity\EntityPersister::executeInserts()` return type changed to `void`

Implementors should adapt to the new signature, and should call
Expand Down
1 change: 0 additions & 1 deletion docs/en/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ Advanced Topics
* :doc:`TypedFieldMapper <reference/typedfieldmapper>`
* :doc:`Improving Performance <reference/improving-performance>`
* :doc:`Caching <reference/caching>`
* :doc:`Partial Objects <reference/partial-objects>`
* :doc:`Change Tracking Policies <reference/change-tracking-policies>`
* :doc:`Best Practices <reference/best-practices>`
* :doc:`Metadata Drivers <reference/metadata-drivers>`
Expand Down
40 changes: 1 addition & 39 deletions docs/en/reference/dql-doctrine-query-language.rst
Original file line number Diff line number Diff line change
Expand Up @@ -518,33 +518,6 @@ when the DQL is switched to an arbitrary join.
- HAVING is applied to the results of a query after
aggregation (GROUP BY)


Partial Object Syntax
^^^^^^^^^^^^^^^^^^^^^

By default when you run a DQL query in Doctrine and select only a
subset of the fields for a given entity, you do not receive objects
back. Instead, you receive only arrays as a flat rectangular result
set, similar to how you would if you were just using SQL directly
and joining some data.

If you want to select partial objects you can use the ``partial``
DQL keyword:

.. code-block:: php
<?php
$query = $em->createQuery('SELECT partial u.{id, username} FROM CmsUser u');
$users = $query->getResult(); // array of partially loaded CmsUser objects
You use the partial syntax when joining as well:

.. code-block:: php
<?php
$query = $em->createQuery('SELECT partial u.{id, username}, partial a.{id, name} FROM CmsUser u JOIN u.articles a');
$users = $query->getResult(); // array of partially loaded CmsUser objects
"NEW" Operator Syntax
^^^^^^^^^^^^^^^^^^^^^

Expand Down Expand Up @@ -1417,15 +1390,6 @@ exist mostly internal query hints that are not be consumed in
userland. However the following few hints are to be used in
userland:


- ``Query::HINT_FORCE_PARTIAL_LOAD`` - Allows to hydrate objects
although not all their columns are fetched. This query hint can be
used to handle memory consumption problems with large result-sets
that contain char or binary data. Doctrine has no way of implicitly
reloading this data. Partially loaded objects have to be passed to
``EntityManager::refresh()`` if they are to be reloaded fully from
the database. This query hint is deprecated and will be removed
in the future (\ `Details <https://github.com/doctrine/orm/issues/8471>`_)
- ``Query::HINT_REFRESH`` - This query is used internally by
``EntityManager::refresh()`` and can be used in userland as well.
If you specify this hint and a query returns the data for an entity
Expand Down Expand Up @@ -1678,10 +1642,8 @@ Select Expressions

.. code-block:: php
SelectExpression ::= (IdentificationVariable | ScalarExpression | AggregateExpression | FunctionDeclaration | PartialObjectExpression | "(" Subselect ")" | CaseExpression | NewObjectExpression) [["AS"] ["HIDDEN"] AliasResultVariable]
SelectExpression ::= (IdentificationVariable | ScalarExpression | AggregateExpression | FunctionDeclaration | "(" Subselect ")" | CaseExpression | NewObjectExpression) [["AS"] ["HIDDEN"] AliasResultVariable]
SimpleSelectExpression ::= (StateFieldPathExpression | IdentificationVariable | FunctionDeclaration | AggregateExpression | "(" Subselect ")" | ScalarExpression) [["AS"] AliasResultVariable]
PartialObjectExpression ::= "PARTIAL" IdentificationVariable "." PartialFieldSet
PartialFieldSet ::= "{" SimpleStateField {"," SimpleStateField}* "}"
NewObjectExpression ::= "NEW" AbstractSchemaName "(" NewObjectArg {"," NewObjectArg}* ")"
NewObjectArg ::= ScalarExpression | "(" Subselect ")"
Expand Down
98 changes: 0 additions & 98 deletions docs/en/reference/partial-objects.rst

This file was deleted.

1 change: 0 additions & 1 deletion docs/en/sidebar.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
reference/query-builder
reference/native-sql
reference/change-tracking-policies
reference/partial-objects
reference/attributes-reference
reference/xml-mapping
reference/php-mapping
Expand Down
5 changes: 0 additions & 5 deletions lib/Doctrine/ORM/Cache/DefaultQueryCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Doctrine\ORM\PersistentCollection;
use Doctrine\ORM\Query;
use Doctrine\ORM\Query\ResultSetMapping;
use Doctrine\ORM\Query\SqlWalker;
use Doctrine\ORM\UnitOfWork;

use function array_map;
Expand Down Expand Up @@ -211,10 +210,6 @@ public function put(QueryCacheKey $key, ResultSetMapping $rsm, mixed $result, ar
throw FeatureNotImplemented::nonSelectStatements();
}

if (($hints[SqlWalker::HINT_PARTIAL] ?? false) === true || ($hints[Query::HINT_FORCE_PARTIAL_LOAD] ?? false) === true) {
throw FeatureNotImplemented::partialEntities();
}

if (! ($key->cacheMode & Cache::MODE_PUT)) {
return false;
}
Expand Down
5 changes: 0 additions & 5 deletions lib/Doctrine/ORM/Cache/Exception/FeatureNotImplemented.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,4 @@ public static function nonSelectStatements(): self
{
return new self('Second-level cache query supports only select statements.');
}

public static function partialEntities(): self
{
return new self('Second level cache does not support partial entities.');
}
}
8 changes: 0 additions & 8 deletions lib/Doctrine/ORM/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,6 @@ final class Query extends AbstractQuery
*/
public const HINT_REFRESH_ENTITY = 'doctrine.refresh.entity';

/**
* The forcePartialLoad query hint forces a particular query to return
* partial objects.
*
* @todo Rename: HINT_OPTIMIZE
*/
public const HINT_FORCE_PARTIAL_LOAD = 'doctrine.forcePartialLoad';

/**
* The includeMetaColumns query hint causes meta columns like foreign keys and
* discriminator columns to be selected and returned as part of the query result.
Expand Down
15 changes: 0 additions & 15 deletions lib/Doctrine/ORM/Query/AST/PartialObjectExpression.php

This file was deleted.

Loading

0 comments on commit 9e1946f

Please sign in to comment.