[MODM-116] Collection Per Class Inheritance : Documents of a child class referenced in a parent class may be saved to the parent collection Created: 07/Feb/11 Updated: 21/Apr/11 |
|
| Status: | Reopened |
| Project: | Doctrine MongoDB ODM |
| Component/s: | Document Manager |
| Affects Version/s: | 1.0.0BETA3 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Critical |
| Reporter: | JF Bustarret | Assignee: | Jonathan H. Wage |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Description |
|
Here is my class hierarchy (classes & attributes renamed for a better understanding) :
/** @Document @InheritanceType("COLLECTION_PER_CLASS") **/
class Parent {
/** @ReferenceOne(targetDocument="Child") **/
protected $child;
}
/** @Document **/
class Child extends Parent {
}
When doing : $parent->setXXX($value); $parent->getChild()->setXXX($value2) the $parent->getChild() document is saved to the Parent collection. It looks like the problems lies in UnitOfWork::executeUpdates :
if (get_class($document) == $className || $document instanceof Proxy && $document instanceof $className) {
$child_document is an instance of Proxy (ChildProxy) and also an instance of Parent => saved using the Parent persister. Shouldn't the test be : get_class($document) == $className || get_class($document) == $className_of_Proxy ? As a side note : why "if ($class->isEmbeddedDocument) { continue; }" is within the foreach and not a "if ($class->isEmbeddedDocument) { return; }" at the beginning of the method ? |
| Comments |
| Comment by Jonathan H. Wage [ 11/Feb/11 ] |
|
I added a test for this here and it appears to be passing: https://github.com/doctrine/mongodb-odm/commit/3f24d77cc04adc0bb5532333e33826100457c666 |
| Comment by JF Bustarret [ 11/Feb/11 ] |
|
I'll try to get more info on the problem and provide a test for it. |
| Comment by JF Bustarret [ 28/Mar/11 ] |
|
Here is a new test case :
/** @Document
* @InheritanceType("COLLECTION_PER_CLASS")
**/
class MODM116Parent
{
/** @Id */
private $id;
/** @String */
private $name;
/** @ReferenceOne **/
private $child;
public function getId()
{
return $this->id;
}
public function getName()
{
return $this->name;
}
public function setName($name)
{
$this->name = $name;
}
public function getChild()
{
return $this->child;
}
public function setChild(MODM116Child $child)
{
$this->child = $child;
}
}
/** @Document **/
class MODM116Child extends MODM116Parent
{
/** @EmbedMany(targetDocument="MODM116Embedded") **/
protected $embedded;
function addEmbedded($parent) {
$this->embedded[] = new MODM116Embedded($parent);
}
}
/** @EmbeddedDocument **/
class MODM116Embedded {
/** @ReferenceOne(targetDocument="MODM116Parent") **/
protected $parent;
public function __construct($parent) {
$this->parent = $parent;
}
}
$parent = new MODM116Parent();
$parent->setName('test');
$parent->setChild(new MODM116Child());
$dm->persist($parent->getChild());
$dm->persist($parent);
$dm->flush();
$dm->clear();
$parent = $dm->getRepository(get_class($parent))->findOneBy(array('name' => 'test'));
$parent->getChild()->setName('ok');
$parent->getChild()->addEmbedded($parent);
$dm->flush();
|
| Comment by JF Bustarret [ 30/Mar/11 ] |
|
Pulled the last version from git. The bug still exists. |
| Comment by JF Bustarret [ 21/Apr/11 ] |
|
Up. Any news on a fix ? |