我试图在Symfony 2.1中序列化带有嵌入文档的MongoDB文档.我正在使用JMSserializer和Mongodb-odm包.
我有以下文件实体.
// Blog
namespace App\DocumentBundle\Document;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
use JMS\SerializerBundle\Annotation\Type;
/**
* @MongoDB\Document(repositoryClass="App\DocumentBundle\Repository\BlogRepository")
*/
class Blog {
/**
* @MongoDB\Id
*/
protected $id;
/**
* @MongoDB\String
* @Assert\NotBlank()
*/
protected $title;
/**
* @MongoDB\string
* @Assert\NotBlank()
*/
protected $blog;
/**
* @MongoDB\EmbedMany(targetDocument="Tag")
*/
private $tags;
/**
* @MongoDB\Timestamp
*/
protected $created;
/**
* @MongoDB\Timestamp
*/
protected $updated;
}
Run Code Online (Sandbox Code Playgroud)
和
// Tag
namespace App\DocumentBundle\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
/**
* @MongoDB\EmbeddedDocument
*/
class Tag …Run Code Online (Sandbox Code Playgroud)