DDC-3798: Allow Collections to be used transparently with Array-Types #4656

Open
opened 2026-01-22 14:46:54 +01:00 by admin · 0 comments
Owner

Originally created by @doctrinebot on GitHub (Jun 29, 2015).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user digitalkaoz:

Currently its not possible to use Collection with Array-Types transparently:

class Entity
{
    /****
     * @var string[]|Collection
     *
     * @ORM\Column(type="json_array")
     */
    private $aliases = [];

    public function **construct()
    {
        $this->aliases  = new ArrayCollection();
    }
}

if i add Values to the Collection and persist the Entity the aliases are empty.
I need Lifecycle Listener which converts between ArrayCollection and array like this:

    /****
     * @ORM\PrePersist
     */
    public function prePersist()
    {
        $this->aliases = $this->aliases->toArray();
    }

it would be good to have an automatic conversion! Should be fairly easy, i could write a PR if your interessted in...or am i missing a hidden piece?

Originally created by @doctrinebot on GitHub (Jun 29, 2015). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user digitalkaoz: Currently its not possible to use Collection with Array-Types transparently: ``` class Entity { /**** * @var string[]|Collection * * @ORM\Column(type="json_array") */ private $aliases = []; public function **construct() { $this->aliases = new ArrayCollection(); } } ``` if i add Values to the Collection and persist the Entity the aliases are **empty**. I need Lifecycle Listener which converts between ArrayCollection and array like this: ``` /**** * @ORM\PrePersist */ public function prePersist() { $this->aliases = $this->aliases->toArray(); } ``` it would be good to have an automatic conversion! Should be fairly easy, i could write a PR if your interessted in...or am i missing a hidden piece?
admin added the Improvement label 2026-01-22 14:46:54 +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#4656