Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Why does Fuel inserting null values to fields?
  • I am inserting new record into DB with using ORM.
    $post = Model_Post::forge(array(
         'title' => Input::post('title'),
         'body' => Input::post('body'),
        ));
    
        if ($post and $post->save()) { // do something }
    

    I get the error:
    Fuel\Core\Database_Exception [ Error ]: SQLSTATE[23000]: Integrity constraint violation: 1048 
    Column 'group' cannot be null with query: "INSERT INTO `posts` (`title`, `body`, `group`, 
    `created_at`, `updated_at`) VALUES ('test', 'testtest', null, 1325284100, 1325284100)"
    

    why does Fuel wants to insert null value into the field 'group'? I have default value in this field set in the posts table. Do I have to always set the Model fields, even if they have default value set in database?
  • Intresting too about validation in models properties and rendering forms. No info in docs .
  • To generate a form from a model, the add_model() method of the Fieldset class is used. The parameters that can be used in the 'form' array of the field properties are the same as can be passed to the Fieldset add() method. Validation is documented under observers.
  • I found error in docs for ORM Model.
    Array key to generate form 'data_type' must be 'type'
  • I think that is already fixed in the development docs.
  • Moved to the ORM forum.
  • The ORM needs to know the values of everything during runtime, thus it auto-populates with null. You can give all the properties default values in the $_properties array that will be set instead of null.
  • Thanks Jelmer, good to know. It is just something it is not mentioned in the docs... In Kohana this was not necessary. The insert SQL would only use the values you specified before calling save() method. I also see I can specifry 'validation' and 'form' keys in the ORM $_properties. How to use them in validation and form generation?

Howdy, Stranger!

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

In this Discussion