Search code examples
controllerkohanaupdating

Kohana 3.1 ORM save()


Is there a syntactical reason that the following would not execute?

$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();

There's a model named fscores. All of the field names are correct. It's not updating the table at all.


Solution

  • As mentioned in the comments - if you want to update, load the record first:

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

    If you don't load it, save method will try to create the record:

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

    Also if you know you're going to update, make it expicit:

    $final_scores->update();