Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REST] DataFilter validating among conditions with multiple operands #16625

Open
az-joss opened this issue Aug 10, 2018 · 1 comment
Open

[REST] DataFilter validating among conditions with multiple operands #16625

az-joss opened this issue Aug 10, 2018 · 1 comment

Comments

@az-joss
Copy link

az-joss commented Aug 10, 2018

What steps will reproduce the problem?

I have configured IndexAction in controller like fallow

    public function actions()
    {
        $actions =  ArrayHelper::merge(
            parent::actions(),
            [
                'index' => [
                    'dataFilter'          => [
                        'class'        => ActiveDataFilter::class,
                        'searchModel'  => function () {
                            return (new \yii\base\DynamicModel([
                                'tags'     => null,
                                'counties' => null,
                            ]))
                                ->addRule('tags', 'each', ['rule' => ['integer']])
                                ->addRule('counties', 'each', ['rule' => ['integer']]);
                        },
                    ]
                ],
            ]
        );

        return $actions;
    }

As you can see, expect to use this attributes like an array of integers
When I use operator in in filter param as fallow:

http://somehost.com/endpoint?filter[tags][in][]=5&filter[tags][in][]=6

Validation of DynamicModel fails because-of passing value not as an array and as each element of an array.
If change DynamicModel rules definision as fallow:

...
     ->addRule('tags', 'integer')
     ->addRule('counties', 'integer');
...

It works fine for IN condition but not for the simple conditions
I've traced it and found this, where loop over an array goes and validator recives element and not all list as expected..

Additional info

Q A
Yii version 2.0.14
PHP version 7.0.30
Operating system MacOS 10.13.6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants