Question

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...

Was it helpful?

Solution

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;
      })
    )
  );
}

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top