【发布时间】:2012-07-11 08:28:21
【问题描述】:
我正在使用来自 git 存储库的 Doctrine MongoDB ODM 和 Symfony2 的主分支以及 mongo 扩展 1.2.10。
我创建了许多类/文档,其注释类似于:
namespace Acme\StoreBundle\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
/**
* @MongoDB\Document
*/
class Person
{
/**
* @MongoDB\Id
*/
protected $id;
/**
* @MongoDB\String(nullable=false)
*/
protected $name;
/**
* @MongoDB\ReferenceOne(targetDocument="PersonType", inversedBy="person", nullable=false)
*/
protected $personType;
}
当我在不设置值或引用的情况下创建并保留一个新文档时,我没有收到任何错误。我是误解了 nullable 选项的使用,需要在生命周期回调中调用验证代码,错误地使用注释,还是 Doctrine 中的错误?
【问题讨论】:
-
当然这是我 Google 搜索中的最后一个链接...link 我假设 nullable 选项的工作方式与 ORM 中的相同,但它实际上控制是否将 null 值存储在数据库。看起来我必须创建一些验证逻辑来强制执行约束。
标签: mongodb symfony doctrine-orm nullable doctrine-odm