[MODM-52] Changes of nested embedded collection are not persisted Created: 18/Aug/10  Updated: 18/Aug/10  Resolved: 18/Aug/10

Status: Resolved
Project: Doctrine MongoDB ODM
Component/s: Persister
Affects Version/s: 1.0.0BETA1
Fix Version/s: 1.0.0BETA2

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


 Description   

When there is a nested EmbedMany collection, changes of this collection are not persisted when saving root document.

Maybe simpler to explain with a test case:

/**
 * @MappedSuperClass
 */
class container
{
    /** @String */
    protected $tmp = 'ensureSaved';

    /** @EmbedMany(targetDocument="emb", cascade="all", strategy="set") */
    protected $items = array();

    function __construct($items = null) {if($items) $this->items = $items;}
    function getItems() {return $this->items;}
    function getItem($index) {return $this->items[$index];}
    function removeItem($i) {unset($this->items[$i]);}
}

/** @EmbeddedDocument */
class emb extends container
{}

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

$emb = new emb(array(new emb(), new emb()));
$doc = new doc(array($emb));

$dm->persist($doc);
$dm->flush();
$dm->refresh($doc);

// change nested embedded collection:
$doc->getItem(0)->removeItem(1);
$before = count($doc->getItem(0)->getItems());

$dm->persist($doc);
$dm->flush();
$dm->refresh($doc);

$after = count($doc->getItem(0)->getItems());
var_dump($before); // outputs 1
var_dump($after);  // outputs 2, but expecting 1


 Comments   
Comment by Vladimir Razuvaev [ 18/Aug/10 ]

I think it might be related to this comment, although not sure.

Comment by Jonathan H. Wage [ 18/Aug/10 ]

Thanks for the issue and test!

Fixed here http://github.com/doctrine/mongodb-odm/commit/3e71c6a6f99360d88c66043ff989d7671e2ded08

Generated at Sat Apr 19 17:27:36 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.