开发者

Issue with persisting specific relation with Doctrine2 ODM

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::$playerChar开发者_开发百科acters

works only on the World side

Looking at it many days, can't find anything different.

  • Tried renaming property names, no change
  • Hydrator entry for character--->world looks identically to others
  • When I add the entry semi-manually (via RockMongo), it works fine
  • Creating the "world" field as NULL makes no difference, with {} it says "Undefined index: $id", but I guess that's an expected behaviour
  • Entities separately work very fine too, it really just is this one relation

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜