Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
syntax to specify default field values
  • hi, as described here (https://github.com/fuel/orm/issues/31) it's not really possible to work with default field values spec'd via the database. unfortunately i'm still not succeeding doing this. i had tried the suggested solution:
    class Model_Example extends Orm\Model {
        protected static $_properties = array(
            'prop' => array(
               'default' => 'value'
             ),
        );
    }
    

    but still am getting exceptions like "Column xy cannot be null" because fuel still tries to write "null" for an empty property. would be glad, if you could help me with this. thanks&best;: jan.
  • hmmm, that's weird - that should work fine. Are you sure you're not overwriting the initial value with "null" yourself?
  • yes, unfortunately i'm pretty sure. i'm taking properties from a request, populate the object with those and try to save. the properties that the orm tries to save explicitely as "null" aren't mentioned in this process at all. var_dump of the object immediately before save:
    object(Model_Project)#57 (7) {
      ["_is_new":"Orm\Model":private]=>
      bool(true)
      ["_frozen":"Orm\Model":private]=>
      bool(false)
      ["_data":"Orm\Model":private]=>
      array(13) {
        ["industry"]=>
        string(2) "02"
        ["url_success"]=>
        string(22) "http://www.success.com";
        ["url_fail"]=>
        string(19) "http://www.fail.com";
        ["url_push"]=>
        string(19) "http://www.push.com";
        ["p_name"]=>
        string(11) "testprojekt"
        ["image"]=>
        string(25) "http://pfad-zu-bildern.de";
        ["color"]=>
        string(11) "z.b. 223421"
        ["id_country"]=>
        string(2) "81"
        ["type"]=>
        NULL
        ["url_param1"]=>
        NULL
        ["url_param2"]=>
        NULL
        ["id_merchant"]=>
        string(6) "843360"
        ["status"]=>
        int(1)
      }
      ["_original":"Orm\Model":private]=>
      array(0) {
      }
      ["_data_relations":"Orm\Model":private]=>
      array(0) {
      }
      ["_original_relations":"Orm\Model":private]=>
      array(0) {
      }
      ["_iterable":protected]=>
      array(0) {
      }
    }
    

    however, the error message is as following:
    Fuel\Core\Database_Exception [ 1048 ]: Column 'force_custom_voucher_ranking' cannot be null [ INSERT INTO
     `vs1_project` (`force_custom_voucher_ranking`, `id_merchant`, `id_industry`, `id_country`, `url_fail`,
     `url_success`, `url_push`, `date_create`, `status`, `industry`, `p_name`, `image`, `color`, `type`, 
    `url_param1`, `url_param2`, `voucher_promotion_display`, `force_custom_promotion_ranking`,
    `always_show_promotions`, `manual_check`, `manual_check_promotions`, `blacklist`) VALUES 
    (NULL, '843360', NULL, '81', 'http://www.fail.com', 'http://www.success.com', 'http://www.push.com', 
    '2011-07-05 12:31:10', 1, '02', 'testprojekt', 'http://pfad-zu-bildern.de', 'z.b. 223421', 
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL) ]
    

    while the properties definition with the test default definition is this:
    protected static $_properties = array('id_project', 'id_merchant', 'id_industry', 'id_country', 'url_fail', 
                                                'url_success', 'url_push' ,'date_create', 'status', 
                                                'industry', 'p_name', 'image', 'color', 'type', 
                                                'url_param1', 'url_param2', 'voucher_promotion_display',
                                                'force_custom_voucher_ranking' => array('default' => '0'),
                                                'force_custom_promotion_ranking', 'always_show_promotions',
                                                'manual_check', 'manual_check_promotions', 'blacklist');
    
  • Are you on RC3? This has only been in as of RC3, RC2 did not yet support default values.
  • ok, there we go. the orm package is still the one from rc2. well, i'll see when we can update safely.. thanks for your help!

Howdy, Stranger!

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

In this Discussion