From c987ad93ca686197d4507d55ae5dc6eff12e6e77 Mon Sep 17 00:00:00 2001 From: Rafis Ganeyev Date: Thu, 20 Aug 2015 15:56:17 +0300 Subject: [PATCH] Add max length validation for CHAR, VARCHAR, TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT fields as default rules set --- classes/Kohana/ORM.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/classes/Kohana/ORM.php b/classes/Kohana/ORM.php index d4348b1..4736626 100644 --- a/classes/Kohana/ORM.php +++ b/classes/Kohana/ORM.php @@ -1149,7 +1149,23 @@ protected function _load_values(array $values) */ public function rules() { - return array(); + $rules = array(); + + foreach ($this->_table_columns as $column => $params) + { + if (is_array($params) && Arr::get($params, 'type') == 'string') + { + $max_length = Arr::get($params, 'character_maximum_length'); + if ( ! is_null($max_length)) + { + $rules[$column][] = array( + 'max_length', array(':value', $max_length) + ); + } + } + } + + return $rules; } /**