Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Trouble saving with ORM
  • This feels like one of those "you're doing it wrong and it's super obvious" types of problems. I'm attempting to update a record that I'm accessing using the ORM. I'm trying to use the method described under "Update" here: http://fuelphp.com/docs/packages/orm/crud.html

    if ($ticket = Ticket::find($id))
    {
    $ticket->status_id = $status_id;
    if ($ticket->save())
    {
    \Session::set_flash('success', 'The status was updated.');
    }
    }

    This code is throwing an error:

    ErrorException [ Error ]: Call to undefined method Orm\Query::save()
  • Should it not be: Model_Ticket::find ?
  • HarroHarro
    Accepted Answer
    You've hit a "feature" that was deprecated in 1.5, and removed in 1.6, because of this problem, and potentionally serious issues.

    1.5 allows you do to find(null), which will return a query object instead of a result. In 1.6, you have to use query() for that, find(null) is no longer allowed.

    So the case here is that $id === null.
  • Sorry, I should have mentioned that $id is not null. The find() method is returning a \Model\Ticket object. I then update the status_id, but the save() method throws the error.
  • Hmm...I see when I dump the $ticket variable that it's not a \Model\Ticket, but rather an \Orm\Query...investigating.
  • PEBCHAK error

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion