我需要为我们的预订存储一些数据,其中包括客户数据,我希望将其作为预订文档中的嵌入文档。 使用我当前的配置,所有数据都保存在MongoDB中,但是当我加载预订文档时,没有相关的客户对象。 我忘记了一些配置或其他什么?
这就是我的文档的样子:
预订文件:
<?php namespace AppBundle\Document; use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB; /** * @MongoDB\Document */ class Booking { /** * @MongoDB\EmbedOne(targetDocument="\AppBundle\Document\Customer") */ private $customer; // getter and setter... }客户文件
<?php namespace AppBundle\Document; use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB; /** * @MongoDB\EmbeddedDocument */ class Customer { // fields, getter and setter }I need to store some data for our booking and thats include the customer data, which I want as embedded document within my booking document. With my current configuration all data are persisted in MongoDB, but when I load the booking document, there is no related customer object. Did I forget some configuration or something else?
This is how my documents look like:
The Booking-Document:
<?php namespace AppBundle\Document; use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB; /** * @MongoDB\Document */ class Booking { /** * @MongoDB\EmbedOne(targetDocument="\AppBundle\Document\Customer") */ private $customer; // getter and setter... }The Customer-Document
<?php namespace AppBundle\Document; use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB; /** * @MongoDB\EmbeddedDocument */ class Customer { // fields, getter and setter }最满意答案
清除缓存。 映射是正常的,因为数据保持正确,错误的是Hydrator已经到位并且没有使用新字段进行更新。 为了避免这种情况,您可以考虑在开发过程中使用AUTOGENERATE_EVAL策略进行水合器/代理自动生成。
Clear your cache. Mapping is OK since the data is persisted correctly, what is wrong is that Hydrator was already in place and wasn't updated with the new field. To avoid such situations you can consider using AUTOGENERATE_EVAL strategy for hydrators/proxies auto-generation during the development.
更多推荐
发布评论