Yii2: exist validator fail on string in integer field

Created on 17 Jan 2018  路  4Comments  路  Source: yiisoft/yii2

What steps will reproduce the problem?

public function rules(): array
{
    return [
        [
            ['id', 'parent_id'],
            'integer',
        ],
        [
            'name',
            'unique',
            'targetAttribute' => ['name', 'parent_id'],
        ],
    ];
}

send post
name = lol
parent_id = fff

What is the expected result?

 correct validate

What do you get instead?

"name": "Database Exception",
"message": "SQLSTATE[22P02]: Invalid text representation: 7 ERROR:  invalid input syntax for integer: \"ffff\"\nThe SQL being executed was: SELECT EXISTS(SELECT * FROM \"osm_region\" WHERE (\"osm_region\".\"name\"='lol') AND (\"osm_region\".\"parent_id\"='ffff'))",

Additional info

| Q | A
| ---------------- | ---
| Yii version | 2.0.13
| PHP version | 7.1
| Operating system | ubuntu

ready for adoption to be verified bug

All 4 comments

Are you sure you do validate() and doesn't do save(false)?

You should use [['id', 'parent_id']', 'filter', 'filter' => 'intval'].

Thank you for your question.
In order for this issue tracker to be effective, it should only contain bug reports and feature requests.

We advise you to use our community driven resources:

If you are confident that there is a bug in the framework, feel free to provide information on how to reproduce it. This issue will be closed for now.

_This is an automated comment, triggered by adding the label question._

I have the same problem, how can I solve it?
FilterValidator didn't work for me
In my case the error occurs when I try to compare the column type integer with an empty string

Was this page helpful?
0 / 5 - 0 ratings