问题
I want to add dummy column in kohana ORM . I have a field of type longtext . I want to have a new field which contains it's strlen.
回答1:
Use $_ignored_columns
property:
protected $_ignored_columns = array('text_length');
public function __get($column)
{
if ($column == 'text_length' && (! isset($this->_object['text_length']) || isset($this->_changed['text'])))
{
// recalc dummy field if not set, or on long text value changing
return $this->_object['text_length'] = strlen($this->_object['text']);
}
return parent::__get($column);
}
来源:https://stackoverflow.com/questions/5659291/adding-dummy-column-in-kohana-orm