开发者

Unexpected doctrine validation error about length when setting the field null

I have a field that is defined as follows:

class Subcategory extends BaseSubcategory {}

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

    // ...
}

Here's what the table looks like:

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

Here's my code to save a record

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

I'm getting the following validation error

* 1 validator failed on meta_description (length)

Why is this happening?


The code samples above do not tell the whole story. I was being misled by an earlier save, in which the meta_description field was being overloaded with over 255 characters. False alarm!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜