0

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

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)

为什么会这样?

4

1 回答 1

0

上面的代码示例并不能说明全部情况。我被早期的保存误导了,其中 meta_description 字段被超过 255 个字符超载。虚惊!

于 2010-08-24T19:53:09.263 回答