条令odm为日期字段返回null


doctrine odm returns null for date field

我将symfony与mongodb-odm原则一起使用。在持久化文档后,我在数据库中获得了正确的数据:

{
  "_id": ObjectID("565572731ba05cb40e000029"),
  "date": ISODate("2015-10-31T23:00:00.000Z"),
  "from": 10,
  "to": 18,
  "type": "work",
  "comment": "",
  "createdOn": ISODate("2015-11-25T08:33:55.000Z")
}

但是,当我尝试在存储库中获取数据时,它会返回null作为日期字段的值。

*edit:我删除了"createdOn"(也是一个日期类型字段),之后它工作得很好。但是,当我的文档中再次有两个日期字段时,它返回了NULL,但现在是"createdOn"字段。

object(AppBundle'Document'Report)#636 (10) {
  ["id":protected]=>
  string(24) "565572731ba05cb40e000029"
  ["date":protected]=>
  NULL
  ["from":protected]=>
  int(10)
  ["to":protected]=>
  int(18)
  ["type":protected]=>
  string(4) "work"
  ["comment":protected]=>
  string(0) ""
  ["createdOn":protected]=>
  object(DateTime)#572 (3) {
    ["date"]=>
    string(26) "2015-11-25 09:33:55.000000"
    ["timezone_type"]=>
    int(3)
    ["timezone"]=>
    string(13) "Europe/Berlin"
  }

}

我尝试使用不同的字段名称(假设"日期"是保留的),但结果是一样的。有人知道为什么它是空的吗?

我的文档类别:

/**
 * @MongoDB'Document(collection="report", repositoryClass="AppBundle'Document'ReportRepository")
 * @HasLifecycleCallbacks 
*/
class Report {
    /** @MongoDB'Id */
    protected $id;
    /** @MongoDB'date */
    protected $date;
    /** @MongoDB'int */
    protected $from;
    /** @MongoDB'int */
    protected $to;
    /** @MongoDB'string */
    protected $type;
    /** @MongoDB'string */
    protected $comment;
    /** @MongoDB'date */
    protected $createdOn;
    /**
     * @MongoDB'PrePersist()
     * @MongoDB'PreUpdate()
     */
    public function prePersist() {
        $this->setCreatedOn(new 'DateTime());
    }

当然还有(生成的)getter和setter。"createdOn"也是一个日期字段,它返回正确的值。

尝试清除缓存:

php应用程序/控制台c:''c