【发布时间】:2014-11-16 05:56:25
【问题描述】:
我有这些课程:
class Country
{
/**
* @MongoDB\Id
*/
protected $id;
/**
* @MongoDB\String
*/
protected $iso;
/**
* @MongoDB\EmbedOne(targetDocument="Localstring")
*/
protected $name;
public function __construct(){
$this->name = new Localstring();
}
}
class Localstring
{
/**
* @MongoDB\Id
*/
private $id;
/**
* @MongoDB\Hash
*/
private $location = array();
}
我想用新的翻译更新每个国家:
$dm = $this->get('doctrine_mongodb')
->getManager();
foreach ($json as $iso => $name) {
$country = $dm->getRepository('ExampleCountryBundle:Country')->findOneByIso($iso);
$localstring_name = $country->getName();
$localstring_name->addTranslation('es_ES', $name);
$dm->flush();
}
如果我在冲洗之前打印一个对象,它会正确打印:
Example\CountryBundle\Document\Country Object ( [id:protected] => 541fe9c678f965b321241121 [iso:protected] => AF [name:protected] => Example\CountryBundle\Document\Localstring Object ( [id:Example\CountryBundle\Document\Localstring:private] => 541fe9c678f965b321241122 [location:Example\CountryBundle\Document\Localstring:private] => Array ( [en_EN] => Afghanistan [es_ES] => Afganistán ) ) )
但在数据库上它不会更新。我尝试更新 $iso 并且它有效。为什么会这样?
【问题讨论】:
标签: mongodb symfony doctrine-orm embed flush