将字段设置为null时,有关长度的意外原则验证错误

时间:2010-08-24 19:37:00

标签: doctrine validation doctrine-1.2

我有一个定义如下的字段:

class Subcategory extends BaseSubcategory {}

abstract class BaseSubcategory extends Doctrine_Record
{
    public function setTableDefinition()
    {
        // ...
        $this->hasColumn('meta_description', 'string', 255);
        // ...
    }

    // ...
}

这是表格的样子:

mysql> DESCRIBE subcategory;
+----------------------+------------------+------+-----+---------+----------------+
| Field                | Type             | Null | Key | Default | Extra          |
+----------------------+------------------+------+-----+---------+----------------+
| id                   | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
[...]
| meta_description     | varchar(255)     | YES  |     | NULL    |                |
[...]
+----------------------+------------------+------+-----+---------+----------------+
10 rows in set (0.00 sec)

这是保存记录的代码

$m = new Subcategory;
// ...
$m->meta_description = null;
$m->save();

我收到以下验证错误

* 1 validator failed on meta_description (length)

为什么会这样?

1 个答案:

答案 0 :(得分:0)

上面的代码示例并不能说明整个故事。我被一个早期的保存误导了,其中meta_description字段被重载超过255个字符。误报!