I am using Doctrine 2 MongoDB ODM, all working fine except 1 specific relation. What's obscure is that I have seemingly identical relations in the project and they all work just fine
namespace Project\Entities\World; // same NS as class, but this is after
// splitting functionality from Entity to MappedSuperclass, didn't work either
/**
* @ReferenceOne(targetDocument="Project\Entities\World")
* @var IWorld
*/
protected $world;
used in Project\Entities\PlayerCharacter (extends Project\Entities\World\Object mentioned above) =>
namespace Project\Entities;
/**
* @Document(collection="worlds")
* @HasLifecycleCallbacks
*/
class World {
/**
* @ReferenceMany(targetDocument="PlayerCharacter")
* @var ArrayCollection
*/
protected $playerCharacters;
}
When I set the $world variable, it's fine in the PHP script. Even $objectManager->refresh($character), $character->getWorld() === $world turns out fine. But it does never appear in the database itself (die right after setting it and flush to make sure it is never changed by accident somewhere) on the PlayerCharacter's end, only on the World side
On the other hand
class PlayerCharacter {
/**
* @ReferenceOne(targetDocument="User")
* @var User
*/
protected $user;
}
=>
/**
* @Document(collection="users")
* @HasLifecycleCallbacks
*/
class User {
/**
* @ReferenceMany(targetDocument="PlayerCharacter")
* @var ArrayCollection
*/
protected $characters;
}
works
In simplified version:
- PlayerCharacter::$user <==(1:N)==> User::$characters
(and all others) are fine, while only
- PlayerCharacter::$world <==(1:N)==> World::$playerCharacters
works only on the World side
Looking at it many days, can't find anything different.
Is there anything I am missing/overlooked or what can I do to discover why is it not getting persisted
(will edit the post if there's need for more info)
Thank you!
Ok, the thing was there were many entries in the UoW some containing World => null and some World => ...WorldProxy, so the latter probably got overwritten
Using flush() before the assignment solved this