Symfony2 + Doctrine mongodb文档生成问题


Symfony2 + Doctrine MongoDM document generation issue

我正在尝试为我的Doctrine Mongo文档类生成getter/setter。

文档代码看起来像这样:

namespace MySite'GameBundle'Document;
use Doctrine'ODM'MongoDB'Mapping'Annotations as MongoDB;
use MySite'GameBundle'Document'User;
/**
 * @MongoDB'Document
 */
class Game {
    /**
     * @ReferenceOne(targetDocument="User")
     */
    protected $user;
    /** @Date */
    protected $start_time;
}

然而,当我尝试使用CLI command php app/console doctrine:mongodb:generate:documents SiteGameBundle生成getter和setter时,我得到以下结果:

[Doctrine'Common'Annotations'AnnotationException]                                                      
  [Semantical Error] The annotation "@ReferenceOne" in property Site'GameBundle'Document'Game::$user was never imported. Did you maybe forget to add a "use" statement for this annotation?

这个问题把我难住了,因为从名称空间的角度来看,我认为我已经正确地包含了所有内容。

您将doctrine注释导入为MongoDB命名空间。所以你应该使用@MongoDB'ReferenceOne,像@MongoDB'Document