Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
can't save an orm model
  • Hello, As for updating a record, I can see that lines in the doc :
    $entry = Model_Article::find(4);
    $entry->title = 'My first edit';
    $entry->author = 'Total n00b';
    $entry->save();
    

    I tried it :
    $projet = Model_Projet::find($id);
    $projet->nom = Input::post('nom');
    $projet->heures_commandees = Input::post('heures');
    $projet->save();
    

    I get the following error :
    ErrorException [ Error ]: Call to undefined method Orm\Query::save() Here is my model :
    class Model_Projet extends Orm\Model 
    {
    
     protected static $_has_many = array('tache');
            protected static $_properties = array('id', 'nom', 'heures_commandees');
            
            public function getProjets() 
            {
                
                return $this->find('all',array('order_by' => array('nom' => 'asc')));
                
            }
    }
    

    I don't understand what I did wrong. Any idea ?
  • I'm sorry I just found the problem : $id was empty :/
    How can I set this message to "fixed" ?
  • If $id is empty, find() will return an instance of \Orm\Query so you can build your own query. It's a common mistake. When you get an error like this, the first thing I would do it var_dump the return value. You would have quickly seen that something else was returned.
  • Hi, I did a print_r of the return value, but I didn't think about $id value.
    I guess my poor brain is overloaded with new things and I forgot old ones... Thanks anyway and sorry for disturbing with such a stupid mistake.
  • It's not that 'stupid', the find() method only returns a Query object on empty for backwards compatibility. It's one of those bad decissions that is hard to fix because too many people are used to it. Your problem explains exactly why this was always a bad idea, the output of a method shouldn't be this ambiguous.

Howdy, Stranger!

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

In this Discussion