1
votes

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
Try with @MongoDB\EmbedOne(targetDocument="Customer") instead.BentCoder
Do CTRL+F and look for mongo here for symfony+mongodb examples. e.g. Simple doctrine mongodb example for EmbedOne in symfonyBentCoder

1 Answers

3
votes

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.