Php Doctrine MongoDB:如果将数据添加到主文档中,则不会保存嵌入的文档
im使用document manager(zend framework 2应用程序)的水合功能将数组数据水合到文档中。 不幸的是,嵌入的子文档不会在数据库中更新(但主文档会更新) 数据的水合作用是正确的,但工作单位不会“注意”子文件的更改 例如: 请求1。。。(创建文档) 请求2。。。(更新现有文档) 对我来说有点奇怪,但是分离子文档会导致更新Php Doctrine MongoDB:如果将数据添加到主文档中,则不会保存嵌入的文档,php,mongodb,doctrine-odm,Php,Mongodb,Doctrine Odm,im使用document manager(zend framework 2应用程序)的水合功能将数组数据水合到文档中。 不幸的是,嵌入的子文档不会在数据库中更新(但主文档会更新) 数据的水合作用是正确的,但工作单位不会“注意”子文件的更改 例如: 请求1。。。(创建文档) 请求2。。。(更新现有文档) 对我来说有点奇怪,但是分离子文档会导致更新 // after detaching sub object the documents will be saved correctly // (but
// after detaching sub object the documents will be saved correctly
// (but this cant be the way it should be...?)
$documentManager->detach($user->getUserAddress());
$documentManager->persist($user);
$documentManager->flush();
以下是注释:
/*
* @ODM\Document(collection="Users")
*/
class User
{
/**
* @ODM\EmbedOne(targetDocument="Document\UserAddress")
*/
protected $address;
//...
/*
* @ODM\EmbeddedDocument()
*/
class UserAddress
{
/**
* @ODM\String
*/
protected $city;
// ...
我错了什么?还是这是一只虫子?或者…水合物功能不是“外部”使用吗?
希望有人能帮助我
问候
诺曼
// after detaching sub object the documents will be saved correctly
// (but this cant be the way it should be...?)
$documentManager->detach($user->getUserAddress());
$documentManager->persist($user);
$documentManager->flush();
/*
* @ODM\Document(collection="Users")
*/
class User
{
/**
* @ODM\EmbedOne(targetDocument="Document\UserAddress")
*/
protected $address;
//...
/*
* @ODM\EmbeddedDocument()
*/
class UserAddress
{
/**
* @ODM\String
*/
protected $city;
// ...