DDC-1219: Remove dependancy on Collection interface in Domain Objects #1532

Closed
opened 2026-01-22 13:17:10 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (Jun 21, 2011).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user anderom:

Short: This issue is all about being able to use doctrine with naked domain objects without any use of doctrine classes.
I 'm not talking about PersistentCollection here, fully aware of that being tied into Doctrine, but those are injected, this is all about code dependency on ArrayCollection.

Seems like some of the UnitOfWork code is cable of handling other types of arrays, like:

    // If $actualData[$name] is not a Collection then use an ArrayCollection.
    if ( ! $actualData[$name] instanceof Collection) {
        $actualData[$name] = new ArrayCollection($actualData[$name]);
    }

But in *cascade functions this is not the case in all but two:

    if ($relatedEntities instanceof Collection) {
        if ($relatedEntities instanceof PersistentCollection) {
            // Unwrap so that foreach() does not initialize

2 however have:

    if (($relatedEntities instanceof Collection || is_array($relatedEntities))) {
        if ($relatedEntities instanceof PersistentCollection) {
            // Unwrap so that foreach() does not initialize

Would it be an idea to do "instanceof Traversable" instead of " instanceof Collection"?

Originally created by @doctrinebot on GitHub (Jun 21, 2011). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user anderom: Short: This issue is all about being able to use doctrine with naked domain objects without any use of doctrine classes. I 'm not talking about PersistentCollection here, fully aware of that being tied into Doctrine, but those are injected, this is all about code dependency on ArrayCollection. Seems like some of the UnitOfWork code is cable of handling other types of arrays, like: ``` // If $actualData[$name] is not a Collection then use an ArrayCollection. if ( ! $actualData[$name] instanceof Collection) { $actualData[$name] = new ArrayCollection($actualData[$name]); } ``` But in *_cascade_ functions this is not the case in all but two: ``` if ($relatedEntities instanceof Collection) { if ($relatedEntities instanceof PersistentCollection) { // Unwrap so that foreach() does not initialize ``` 2 however have: ``` if (($relatedEntities instanceof Collection || is_array($relatedEntities))) { if ($relatedEntities instanceof PersistentCollection) { // Unwrap so that foreach() does not initialize ``` Would it be an idea to do "instanceof Traversable" instead of " instanceof Collection"?
admin added the Improvement label 2026-01-22 13:17:10 +01:00
admin closed this issue 2026-01-22 13:17:10 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jun 21, 2011):

Comment created by anderom:

Note: If the fist code block is always performed before the last 2 blocks then there is no issue here, just a need to make it more clear in Doc that this is possible but that you should not rely custom implementation as PersistentCollection will be injected when loaded from db.

@doctrinebot commented on GitHub (Jun 21, 2011): Comment created by anderom: Note: If the fist code block is always performed before the last 2 blocks then there is no issue here, just a need to make it more clear in Doc that this is possible but that you should not rely custom implementation as PersistentCollection will be injected when loaded from db.
Author
Owner

@beberlei commented on GitHub (Feb 16, 2020):

ArrayCollection is from the doctrine/collections package, which has nothing to do with persistence. Its not desirable to support native arrays or traversables here, because they can't always work with Doctrine internal magic.

@beberlei commented on GitHub (Feb 16, 2020): ArrayCollection is from the `doctrine/collections` package, which has nothing to do with persistence. Its not desirable to support native arrays or traversables here, because they can't always work with Doctrine internal magic.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1532