【问题标题】:Kohana 3.1 ORM save()Kohana 3.1 ORM 保存()
【发布时间】:2012-11-01 19:26:39
【问题描述】:

是否存在以下无法执行的语法原因?

$final_scores = ORM::factory('fscores');
$final_scores->userid = $userid;
$final_scores->es1 = $self_awr;
$final_scores->es2 = $self_mgt;
$final_scores->es3 = $social_awr;
$final_scores->es4 = $rel_mgt;
$final_scores->save();

有一个名为 fscores 的模型。所有字段名称都是正确的。它根本没有更新表格。

【问题讨论】:

  • 更新需要先选择型号。
  • 是的,更新前必须加载模型。

标签: controller kohana updating


【解决方案1】:

如 cmets 中所述 - 如果要更新,请先加载记录:

$final_scores = ORM::factory('fscores', $your_id_for_update);

如果不加载,save方法会尝试创建记录:

public function save(Validation $validation = NULL)
{
    return $this->loaded() ? $this->update($validation) : $this->create($validation);
}

另外,如果您知道要更新,请明确说明:

$final_scores->update();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-04
    • 2011-08-06
    • 1970-01-01
    • 1970-01-01
    • 2011-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多