[PR #5800] Allow using custom collections #9733

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

Original Pull Request: https://github.com/doctrine/orm/pull/5800

State: closed
Merged: No


Current situation

When querying the DB, Doctrine retrieves the 1-n and n-n associations in its own collection, the PersistentCollection, and the query result set as an array. As this is a specific DoctrineCollection, tied to the implementation, it is currently impossible to specify a Domain Collection to be used instead of the PersistentCollection.

Proposed enhancement

Allow to specify a Collection for each entity type, to be used when retrieving 1-n and n-n relations, as well as the query result set .

The specified collection must be extended from PersistentCollection, in order to maintain the persistence capabilities of the associations. If the specified collection is not extended from PersistentCollection, an ORMInvalidArgumentException will be thrown.
If a collection is not specified, Doctrine will maintain the current behavior of using a PersistentCollection. I understand that this ties the domain collections to the ORM, but I feel that having this functionality is more important than that, also because it is not mandatory to use this functionality, it is completely optional for the developer to do so or not.

The query result set however will still be an array, as it is the current behavior of Doctrine and changing it would break BC. This, however, can be changed by adding an option to override the default behavior and return the query result set as the collection specified for the entities returned in the query result set.

This PR somewhat relates to:

**Original Pull Request:** https://github.com/doctrine/orm/pull/5800 **State:** closed **Merged:** No --- ### Current situation When querying the DB, Doctrine retrieves the 1-n and n-n associations in its own collection, the PersistentCollection, and the query result set as an array. As this is a specific DoctrineCollection, tied to the implementation, it is currently impossible to specify a Domain Collection to be used instead of the PersistentCollection. ### Proposed enhancement Allow to specify a Collection for each entity type, to be used when retrieving 1-n and n-n relations, as well as the query result set . The specified collection must be extended from PersistentCollection, in order to maintain the persistence capabilities of the associations. If the specified collection is not extended from PersistentCollection, an ORMInvalidArgumentException will be thrown. If a collection is not specified, Doctrine will maintain the current behavior of using a PersistentCollection. I understand that this ties the domain collections to the ORM, but I feel that having this functionality is more important than that, also because it is not mandatory to use this functionality, it is completely optional for the developer to do so or not. The query result set however will still be an array, as it is the current behavior of Doctrine and changing it would break BC. This, however, can be changed by adding an option to override the default behavior and return the query result set as the collection specified for the entities returned in the query result set. This PR somewhat relates to: - https://github.com/doctrine/doctrine2/issues/5057 - https://github.com/doctrine/doctrine2/commits/custom-collections
admin added the pull-request label 2026-01-22 16:05:15 +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#9733