Copy changes made to $this->data in beforeValidate callbacks #642

Merged
merged 1 commit into from May 9, 2012

Conversation

Projects
None yet
3 participants
Member

jippi commented May 9, 2012

Back to saveAssociated data variable

This allow changes in beforeValidate to be saved

Code like this will not work without this patch

It used to work in 1.3 and 2.0


<?php
class DemoModel extends AppModel {
    public function beforeValidate() {
        $this->data[$this->alias]['test'] = 1;
        return parent::beforeValidate();
    }

    public function beforeSave($options = array()) {
        if (empty($this->data[$this->alias]['test'])) {
            die('fail');
        }
        die('ok');
    }
}
@jippi jippi Copy changes made to $this->data in beforeValidate callbacks back to …
…saveAssociated data variable

This allow changes in beforeValidate to be saved
45a86a8
Owner

lorenzo commented May 9, 2012

Thanks!

@lorenzo lorenzo added a commit that referenced this pull request May 9, 2012

@lorenzo lorenzo Merge pull request #642 from nodesagency/hotfix/beforeValidate-copy-data
Copy changes made to $this->data in beforeValidate callbacks
6bd7da3

@lorenzo lorenzo merged commit 6bd7da3 into cakephp:2.1 May 9, 2012

aroc commented Aug 24, 2012

I can't get this to work in Cake 1.3.15 - changes to model's data array made in a behaviours beforeValdiate() method show up as changed when dumped in the Model's beforeSave(), however they do not save to the database.

Any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment