DDC-232: toArray of PersistentCollection returns an empty collection #286

Closed
opened 2026-01-22 12:33:33 +01:00 by admin · 4 comments
Owner

Originally created by @doctrinebot on GitHub (Jan 3, 2010).

Jira issue originally created by user cloun:

I've found little error in the class Doctrine\ORM\PersistentCollection in method toArray. There is lost calling of _initialize method probably. This leads to abnormal behavior:

class Role
{
...
/****

  • @ManyToMany(targetEntity="Resource")
  • @JoinTable(name="access",
  • joinColumns={@JoinColumn(name="role_id", referencedColumnName="role_id")},
  • inverseJoinColumns={@JoinColumn(name="resource_id", referencedColumnName="resource_id")}
  • )
    */
    private $resources;
    public function makeTest()
    {
    echo count($this->resources->toArray()) . "\n";
    echo count($this->resources) . "\n";
    }
    ...
    }

Output:
0
1

Originally created by @doctrinebot on GitHub (Jan 3, 2010). Jira issue originally created by user cloun: I've found little error in the class Doctrine\ORM\PersistentCollection in method toArray. There is lost calling of _initialize method probably. This leads to abnormal behavior: class Role { ... /**** - @ManyToMany(targetEntity="Resource") - @JoinTable(name="access", - joinColumns={@JoinColumn(name="role_id", referencedColumnName="role_id")}, - inverseJoinColumns={@JoinColumn(name="resource_id", referencedColumnName="resource_id")} - ) */ private $resources; public function makeTest() { echo count($this->resources->toArray()) . "\n"; echo count($this->resources) . "\n"; } ... } Output: 0 1
admin added the Bug label 2026-01-22 12:33:34 +01:00
admin closed this issue 2026-01-22 12:33:34 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jan 3, 2010):

@doctrinebot commented on GitHub (Jan 3, 2010): - duplicates [DDC-216: PersistentCollection#toArray() should call _initialize()](http://www.doctrine-project.org/jira/browse/DDC-216)
Author
Owner

@doctrinebot commented on GitHub (Jan 5, 2010):

Comment created by romanb:

Should be fixed now.

@doctrinebot commented on GitHub (Jan 5, 2010): Comment created by romanb: Should be fixed now.
Author
Owner

@doctrinebot commented on GitHub (Jan 5, 2010):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Jan 5, 2010): Issue was closed with resolution "Fixed"
Author
Owner

@doctrinebot commented on GitHub (Jan 5, 2010):

Comment created by cloun:

Thanks

@doctrinebot commented on GitHub (Jan 5, 2010): Comment created by cloun: Thanks
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#286