doctrine/mongodb-odm — Issue #190: issue with id strategy autoincrement
Author: cbou
Created: 2011-11-10 10:37:26+00:00
State: open

I have a many to one relation between two documents.
I search the parent document in the database and make modifications on children documents.
I call the persist and flush methods, but the children document are not updated.

This issue does not appear if the children document IDs have the default strategy.

Example:

```php

$parentDocument = $dm->getRepository('Parent')->find($id);
foreach ($parentDocument->getChildren() as $child) {
$s->setName('Child');
$dm->persist($s);
}
$dm->persist($parent);
$dm->flush();

```

Here are the docuement definitions:

```php

update() into:

```php

/** @override */
public function update($query, array $newObj, array $options = array())
{
if ($this->eventManager->hasListeners(Events::preUpdate)) {
$this->eventManager->dispatchEvent(Events::preUpdate, new UpdateEventArgs($this, $query, $newObj));
}
$query['_id'] = (float)$query['_id']; // HERE IS MY CHANGE
$result = $this->doUpdate($query, $newObj, $options);

if ($this->eventManager->hasListeners(Events::postUpdate)) {
$this->eventManager->dispatchEvent(Events::postUpdate, new EventArgs($this, $result));
}

return $result;
}

```

And it works. Obviously just with autoincrement strategy, it's not a fix :p

Sorry, I'm not sure if it's a Doctrine MongoDB ODM or a Doctrine MongoDB or a PHP MongoDB Driver issue...