我在文档描述中添加了新条目
/**
* @MongoDB'Field(type="string")
*/
protected $city;
然后让条令生成实体。现在,新创建的记录具有新字段"city",其值与预期值一致。然而,我只能在mongo控制台中看到这些值。在条令输出中,它们都被设置为"空"。实体条目似乎正确
public function getFirstName()
{
return $this->firstName;
}
/**
* Get city
*
* @return string $city
*/
public function getCity()
{
return $this->city;
}
我有仓库
public function allQuery($cat)
{
$q = $this->createQueryBuilder()
->sort('createdAt', 'DESC');
if ($cat) {
$q->field('category.$id')->equals(new 'MongoId($cat));
}
return $q;
}
和服务
function addAllPager($perPage = 10, $cat)
{
return $this->_addPager($this->repo()->allQuery($cat), $perPage);
}
控制器内
$helper = $this->get('appbundle.test.helper');
$tests = $helper->addAllPager(10, $cat);
Symfony探查器向我显示查询db.Test.find().sort({ "createdAt": -1 }).limit(10).skip(0)
。$tests 的转储内容
#firstName: "John"
#city: null
我缺少什么?
编辑
用php bin/console cache:clear
清除缓存解决了这个问题。php bin/console doctrine:mongodb:cache:clear-metadata
是不够的。感谢malarzm
。
我知道这是在提出问题8个月后,但有同样的问题,并与学说斗争了一段时间。我正在使用Symfony 3,我尝试了php bin/console doctrine:mongodb:cache:clear-metadata
,但没有成功。
我最终运行了命令php bin/console cache:clear
,或者只是用命令sudo rm -rf var/cache
删除缓存,这就解决了问题。