문제

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

도움이 되었습니까?

해결책

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

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top