问题
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
}
回答1:
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.
来源:https://stackoverflow.com/questions/43866068/doctrine-odm-mongodb-embedone-document-not-loaded