Cakephp指定要保存的字段?

时间:2011-03-14 02:19:26

标签: php mysql sql cakephp insert

在我的模型中,我有一个名为difficulty的字段,但无论我给它什么值,都会将值1保存到数据库中。

在我执行save()之前,我在模型上做了一个datadump,这就是我所看到的:

Array
(
    [title] => testtt34
    [serves] => 32
    [prep_time] => 32
    [cooking_time] => 32
    [difficulty] => 4
)

但生成的sql查询cakephp是:

INSERT INTO `recipes` (`title`, `serves`, `prep_time`, `cooking_time`, `difficulty`, `modified`, `created`) VALUES ('testtt34', 32, 32, 32, 1, '2011-03-13 19:15:16', '2011-03-13 19:15:16')

到底是什么?即使我的datadump中的难度明显为4,但生成的sql插入难度= 1。

//Do some checking to make sure the data is from proper location
$this->data = Sanitize::clean($this->data);
$this->Recipe->data = $this->data;
//error checking
$this->pa($this->Recipe->data['Recipe']);
if ($this->Recipe->save())
{
    //Blah do some stuff
}

1 个答案:

答案 0 :(得分:0)

没关系我不小心设置了难度的类型,因为TINYINT(1)意味着要做TINYINT(3),那就修好了。非常愚蠢的错误。