Cakephp 3.-7: Validate only one field


#1

Hi

I would like to validate only one field although the requestData has multiple ones.

I have thought

        $user = $this->Users->patchEntity(
            $user,
            $this->request->getData(),
            [
            'fields' => ['key']
            ]
        );

must work, but it doesnt - all fields will still be validated.

Whats wrong here?

Thanks,
Frank


#2

Where are you getting the fields idea from? Looking at the source, I see options for accessibleFields and fieldList in patchEntity (both referenced in the documentation, but no sign of fields.

If you want to only validate one field, you need to use custom validation.