FriendsOfCake / cakephp-upload

CakePHP: Handle file uploading sans ridiculous automagic
https://cakephp-upload.readthedocs.io/
MIT License
551 stars 255 forks source link

manual saving not working #468

Closed anuj9196 closed 7 years ago

anuj9196 commented 7 years ago

In some parts of my web application, I need to manually save field values.

On manual saving like

$updateFile = $this->PostVideos->newEntity();

$updateFile = $this->PostVideos->patchEntity($updateFile, [
    'video_file' => 'inspiration.mp4',
    'dir' => 'new/path/to/video/file'
], [
    'validate' => false
]);

debug($updateFile);

if ($a = $this->PostVideos->save($updateFile)) {
    debug($a);
}

All fields are saving except video_file. The field remains null

After removing behaviour

    $this->addBehavior('Josegonzalez/Upload.Upload', [
            'video_file' => [
                'path' => 'webroot{DS}files{DS}{model}{DS}{field}{DS}{microtime}{DS}',
                'fields' => [
                    'dir' => 'dir', // defaults to `dir`
                ],
                'keepFilesOnDelete' => false,
            ],
        ]);

All works fine.

jorisvaesen commented 7 years ago

You could remove the behavior on the fly: https://book.cakephp.org/3.0/en/orm/behaviors.html#removing-loaded-behaviors