Skip to content

Commit

Permalink
Bug fixed. saveAll with validation option "only" or "first" works wll.
Browse files Browse the repository at this point in the history
saveAll() did set null foreign key when it just validates. I've
assigned numeric validation on the hasMany side model and validation
did fail with this behavior. I've changed this not to set foreign key
when it just validation.
  • Loading branch information
Yosuke Basuke Suzuki committed Sep 23, 2011
1 parent a65a5eb commit eef87ee
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions cake/libs/model/model.php
Expand Up @@ -1687,7 +1687,10 @@ function saveAll($data = null, $options = array()) {
$type = $associations[$association];
switch ($type) {
case 'hasOne':
$values[$this->{$type}[$association]['foreignKey']] = $this->id;
if (!$validating) {
$values[$this->{$type}[$association]['foreignKey']] = $this->id;
}

if (!$this->{$association}->__save($values, $options)) {
$validationErrors[$association] = $this->{$association}->validationErrors;
$validates = false;
Expand All @@ -1697,9 +1700,12 @@ function saveAll($data = null, $options = array()) {
}
break;
case 'hasMany':
foreach ($values as $i => $value) {
$values[$i][$this->{$type}[$association]['foreignKey']] = $this->id;
if (!$validating) {
foreach ($values as $i => $value) {
$values[$i][$this->{$type}[$association]['foreignKey']] = $this->id;
}
}

$_options = array_merge($options, array('atomic' => false));

if ($_options['validate'] === 'first') {
Expand Down

0 comments on commit eef87ee

Please sign in to comment.