Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Merged
merged 1 commit into from

3 participants

@jippi
Collaborator

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
@lorenzo
Owner

Thanks!

@lorenzo lorenzo merged commit 6bd7da3 into from
@aroc

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
Commits on May 9, 2012
  1. @jippi

    Copy changes made to $this->data in beforeValidate callbacks back to …

    jippi authored
    …saveAssociated data variable
    
    This allow changes in beforeValidate to be saved
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 0 deletions.
  1. +1 −0  lib/Cake/Model/Model.php
View
1  lib/Cake/Model/Model.php
@@ -2178,6 +2178,7 @@ public function saveAssociated($data = null, $options = array()) {
if ($options['validate'] === 'first') {
$validates = $this->validateAssociated($data, $options);
+ $data = $this->data;
if ((!$validates && $options['atomic']) || (!$options['atomic'] && in_array(false, $validates, true))) {
return $validates;
}
Something went wrong with that request. Please try again.