douju8782
2011-03-14 02:19
浏览 26
已采纳

Cakephp指定要保存的字段?

In my model, I have a field called difficulty, but no matter what value i give it, a value of 1 is saved to the database.

I did a datadump on the model before I did a save() and this is what I see:

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

But the sql query cakephp generated is this:

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')

What the heck? even though difficulty is clearly 4 in my datadump, the sql generated inserted difficulty = 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条回答 默认 最新

  • dshxbrzgi090608692 2011-03-14 02:27
    已采纳

    Nevermind I accidentally set difficulty's type as TINYINT(1) meant to do TINYINT(3), well that fixed it. Very dumb mistake.

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题