msoa
June 26, 2013, 6:55pm
1
Hi,
Expose there is a table with two fields: id(INT) and status(TINYINT)
When creating model with Gii will be create two rule for the attributes:
array('status', 'numerical', 'integerOnly'=>true),
array('id', 'length', 'max'=>10),
Why id considered as string but status as integer?
konapaz
(Konapaz)
June 26, 2013, 10:27pm
2
Are you sure?
run from sql command "DESCRIBE yourtable"
also which is your database ?
msoa
June 27, 2013, 1:19am
3
Table:
[sql]CREATE TABLE test
( id
INT NULL , status
INT UNSIGNED NULL );[/sql]
Rules:
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('id', 'numerical', 'integerOnly'=>true),
array('id2', 'length', 'max'=>10),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, id2', 'safe', 'on'=>'search'),
);
}
Int fields with UNSIGNED flag were considered as String .
konapaz
(Konapaz)
June 27, 2013, 7:53am
4
msoa:
Table:
[sql]CREATE TABLE test
( id
INT NULL , status
INT UNSIGNED NULL );[/sql]
Rules:
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('id', 'numerical', 'integerOnly'=>true),
array('id2', 'length', 'max'=>10),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, id2', 'safe', 'on'=>'search'),
);
}
Int fields with UNSIGNED flag were considered as String .
It is very strange, please re-generate the model by gii (use another php name file) and post entire code,
also what sql do you use? (mysql, sqlserver etc)
msoa
June 27, 2013, 10:31am
5
KonApaz:
It is very strange, please re-generate the model by gii (use another php name file) and post entire code,
also what sql do you use? (mysql, sqlserver etc)
Dear friend, i try it several times(with another php file name). but each time the result was same. i use MySQL. Do you try it?
konapaz
(Konapaz)
June 27, 2013, 10:54am
6
Yes I just try it, You are right!
Something is wrong on fetching table schema, may be a bug of Yii or mysql driver.
The ‘unsigned int’ returns type “string” to Gii generator so
array('status', 'length', 'max'=>10)
generated
konapaz
(Konapaz)
June 27, 2013, 11:00am
7
KonApaz:
Yes I just try it, You are right!
Something is wrong on fetching table schema, may be a bug of Yii or mysql driver.
The ‘unsigned int’ returns type “string” to Gii generator so
array('status', 'length', 'max'=>10)
generated
check these
http://www.doctrine-project.org/jira/browse/DBAL-394
http://bugs.mysql.com/bug.php?id=52007
but the most important is
msoa
June 28, 2013, 1:28am
8
So, we need need to fix it manually(The rules generated with Gii).