2

In Kohana 3.2, when you overwrite the function 'values' of the ORM, and then do something like:

public function values(array $values, array $expected = NULL) {           

  if($values['a_column'] == "") $values['a_column'] = NULL;

  return parent::values($values);
}

the NULL value will be transformed into an empty string anyway, which is not the behaviour I want. Anyone knows a workaround? I couldn't find anything in the documentation or on the web...

Pierre
  • 4,976
  • 12
  • 54
  • 76

2 Answers2

5

I discovered the answer to this. Just use a filter in your model, like so:-

public function filters()
{
  return array(
    'initial_assessment_date' => array(
      array(function($value) {
        return (!$value) ? NULL : $value;
      })
    )
  );
}
1

This is because later ORM::values use array_key_exists. You need to use unset to remove the value.

Federkun
  • 36,084
  • 8
  • 78
  • 90
  • 1
    I had thought about that and it works on a create, but not on an update, since unsetting will leave the db value unchanged... – Pierre Jul 19 '12 at 16:48
  • The lack of this functionality is , quite frankly, astonishing for me. –  Sep 26 '12 at 19:26