Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
I am not getting the primary key after ->save();
  • From the docs....

    "
    After save() the model has been saved to the database and if you're using an auto_increment primary key it will automatically be set on the instance after successful saving it."

    I am using an auto_increment primary key.

    I have a simple model.  I populate it, save it and go look for the id but it is always 0.

     $recur = Cal\Model_Calendar_Recurrence::forge();
     $recur->freq = Input::post('freq');
    ....   
    if( $recur->save()){
    $recur_id_ = $recur->id;
    } else {

    }

    The model has a _primary_key that = 'id''
    The row in the database has an id = 7
    The _properties id = 0
    The _data id = 0

    What is happening?  I think I ran into this before and simply wrote my own "new_object" method and use that, but you would think it should work.  What am I doing wrong?



  • I will leave this here, although, I doubt anyone will do something as stupid as I did here....   

    I had set the default to "0" in the Model properties.   And that is why it was always 0.

            'id' => array(
                'default' => 0,
            ),

    Once I removed the default all works as expected.

Howdy, Stranger!

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

In this Discussion