{"action":"created","issue":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/9756","labels_url":"https://api.github.com/repos/yiisoft/yii2/issues/9756/labels{/name}","comments_url":"https://api.github.com/repos/yiisoft/yii2/issues/9756/comments","events_url":"https://api.github.com/repos/yiisoft/yii2/issues/9756/events","html_url":"https://github.com/yiisoft/yii2/issues/9756","id":107894557,"number":9756,"title":"Different rules with default min/max values for different kind of field types","user":{"login":"shamyyl","id":8983206,"avatar_url":"https://avatars.githubusercontent.com/u/8983206?v=3","gravatar_id":"","url":"https://api.github.com/users/shamyyl","html_url":"https://github.com/shamyyl","followers_url":"https://api.github.com/users/shamyyl/followers","following_url":"https://api.github.com/users/shamyyl/following{/other_user}","gists_url":"https://api.github.com/users/shamyyl/gists{/gist_id}","starred_url":"https://api.github.com/users/shamyyl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shamyyl/subscriptions","organizations_url":"https://api.github.com/users/shamyyl/orgs","repos_url":"https://api.github.com/users/shamyyl/repos","events_url":"https://api.github.com/users/shamyyl/events{/privacy}","received_events_url":"https://api.github.com/users/shamyyl/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/yiisoft/yii2/labels/feature:gii","name":"feature:gii","color":"bfd4f2"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-09-23T10:53:08Z","updated_at":"2015-09-23T13:38:43Z","closed_at":null,"body":"I have int4 field in my postgres database table. Gii generates for this field \"integer\" rule without default min/max values. \r\nSo when i try to add 4 000 000 000 value in this field postgres throws the exeption: \r\n```\r\n\"4000000000\" is not a valid integer value.\r\n```\r\nOk.\r\nI don\\`t want to add for all my models min/max values in integer rules and override ```init()``` method in ``` yii\\validators\\NumberValidator```:\r\n```php\r\nnamespace app\\components\\validators;\r\nclass NumberValidator extends \\yii\\validators\\NumberValidator\r\n{\r\n    public function init()\r\n    {\r\n        if ($this->max === null && $this->integerOnly) {\r\n            $this->max = 2147483647;\r\n        }\r\n\r\n        if ($this->min === null && $this->integerOnly) {\r\n            $this->min = -2147483648;\r\n        }\r\n\r\n        parent::init();\r\n    }\r\n} \r\n```\r\nand add the next code in index.php:\r\n```php\r\n\\Yii::$container->set(\r\n        'yii\\validators\\NumberValidator',\r\n        ['class' => '\\app\\components\\validators\\NumberValidator']\r\n    );\r\n```\r\nBut khow validation return false, when i try add 4 000 000 000 value in int8 field, because gii generate \"integer\" rule for int2, int4 and int8 fields:\r\n```php\r\nnamespace yii\\gii\\generators\\model;\r\nclass Generator extends \\yii\\gii\\Generator\r\n{\r\n    public function generateRules($table)\r\n    {\r\n     ...\r\n            switch ($column->type) {\r\n                case Schema::TYPE_SMALLINT:\r\n                case Schema::TYPE_INTEGER:\r\n                case Schema::TYPE_BIGINT:\r\n                    $types['integer'][] = $column->name;\r\n                    break;\r\n       ...\r\n      }\r\n}\r\n```\r\n\r\n**What about create different rules with default min/max values for different kind of field types?**\r\n\r\nSomething like this:\r\n```php\r\nnamespace yii\\gii\\generators\\model;\r\nclass Generator extends \\yii\\gii\\Generator\r\n{\r\n    public function generateRules($table)\r\n    {\r\n     ...\r\n            switch ($column->type) {\r\n                case Schema::TYPE_SMALLINT:\r\n                    $types['smallint'][] = $column->name;\r\n                    break;\r\n                case Schema::TYPE_INTEGER:\r\n                    $types['integer'][] = $column->name;\r\n                    break;\r\n                case Schema::TYPE_BIGINT:\r\n                    $types['bigint'][] = $column->name;\r\n                    break;\r\n       ...\r\n      }\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/comments/142603897","html_url":"https://github.com/yiisoft/yii2/issues/9756#issuecomment-142603897","issue_url":"https://api.github.com/repos/yiisoft/yii2/issues/9756","id":142603897,"user":{"login":"samdark","id":47294,"avatar_url":"https://avatars.githubusercontent.com/u/47294?v=3","gravatar_id":"","url":"https://api.github.com/users/samdark","html_url":"https://github.com/samdark","followers_url":"https://api.github.com/users/samdark/followers","following_url":"https://api.github.com/users/samdark/following{/other_user}","gists_url":"https://api.github.com/users/samdark/gists{/gist_id}","starred_url":"https://api.github.com/users/samdark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samdark/subscriptions","organizations_url":"https://api.github.com/users/samdark/orgs","repos_url":"https://api.github.com/users/samdark/repos","events_url":"https://api.github.com/users/samdark/events{/privacy}","received_events_url":"https://api.github.com/users/samdark/received_events","type":"User","site_admin":false},"created_at":"2015-09-23T13:38:42Z","updated_at":"2015-09-23T13:38:42Z","body":"Well, the output of Gii is meant to be corrected and I think if there's min/max it is easier to correct it than to add such validator from scratch.\r\n\r\nIf you have an idea how to support it for all databases and types, propose solution."}}