与 Doctrine2 ODM 持续存在特定关系的问题

发布于 2024-11-28 11:23:54 字数 1849 浏览 0 评论 0原文

我正在使用Doctrine 2 MongoDB ODM,除了 1 个特定关系之外,一切都工作正常。令人费解的是,我在项目中具有看似相同的关系,并且它们都

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;

在 Project\Entities\PlayerCharacter 中使用得很好(上面提到的 extends Project\Entities\World\Object) =>

namespace Project\Entities;

/**
 * @Document(collection="worlds")
 * @HasLifecycleCallbacks
 */
class World {
    /**
 * @ReferenceMany(targetDocument="PlayerCharacter")
 * @var ArrayCollection
 */
protected $playerCharacters;
}

当我设置 $world 变量时,它在 PHP 脚本中没问题。即使 $objectManager->refresh($character), $character->getWorld() === $world 结果也很好。但它永远不会出现在数据库本身中(在设置它并刷新后立即死亡以确保它不会在某个地方意外更改)出现在PlayerCharacter端,仅出现在世界端

另一方面

class PlayerCharacter {
/**
 * @ReferenceOne(targetDocument="User")
 * @var User
 */
protected $user;
 }

= >

/**
 * @Document(collection="users")
 * @HasLifecycleCallbacks
 */
class User {
    /**
     * @ReferenceMany(targetDocument="PlayerCharacter")
     * @var ArrayCollection
     */
    protected $characters;
}

简化版本中的作品


- PlayerCharacter::$user <==(1:N)==>用户::$字符
(和所有其他)都很好,但只有
- PlayerCharacter::$world <==(1:N)==>世界::$playerCharacters
仅适用于世界一侧

看了很多天,找不到任何不同。

  • 尝试重命名属性名称,没有改变
  • 字符的水合器条目--->世界看起来与其他条目相同
  • 当我半手动添加条目(通过RockMongo)时,它工作正常
  • 将“世界”字段创建为NULL没有什么区别, {} 它说“未定义的索引:$id”,但我想这是一种预期的行为
  • 实体单独工作也非常好,它实际上只是这个关系

是否有什么我遗漏/忽略的或者我可以做什么来发现为什么它没有得到持久化

(如果需要更多信息,将编辑帖子)

谢谢!

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.

  • 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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心房的律动 2024-12-05 11:23:54

好吧,问题是 UoW 中有很多条目,其中一些包含 World => null 和一些世界 => ...WorldProxy,因此后者可能

在分配解决此问题之前使用flush()被覆盖

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文