[MODM-49] Getting PHP notice and warning with empty persistent collection Created: 17/Aug/10  Updated: 17/Aug/10  Resolved: 17/Aug/10

Status: Resolved
Project: Doctrine MongoDB ODM
Component/s: Collections
Affects Version/s: None
Fix Version/s: 1.0.0BETA1

Type: Bug Priority: Major
Reporter: Vladimir Razuvaev Assignee: Jonathan H. Wage
Resolution: Fixed Votes: 0
Labels: None


 Description   

If there is an object with empty collection, e.g.:

{
  "_id": "4c6a11810f9d503c03000000",
  "b": [
  ]
}

Then following code produces notice and warning:

/** @Document(db="tests", collection="tests") */
class a
{
    /** @Id */
    protected $id;

    /** @ReferenceMany(targetDocument="b", cascade="persist") */
    protected $b;

    function getB()   {return $this->b;}
}

/** @Document(db="tests", collection="tests2") */
class b
{
    /** @Id */
    protected $id;
}

$a = $dm->loadByID('a', '4c6a11810f9d503c03000000');
echo count($a->getB()); // produces notice and warning

Notice and warning text:

Notice: Undefined variable: groupedIds in library\Doctrine\ODM\MongoDB\PersistentCollection.php on line 122

Warning: Invalid argument supplied for foreach() in library\Doctrine\ODM\MongoDB\PersistentCollection.php on line 122


 Comments   
Comment by Jonathan H. Wage [ 17/Aug/10 ]

This is fixed now.

Generated at Fri Sep 19 11:51:16 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.