Skip to content

Commit

Permalink
Add foreignKey to whitelist in saveAssociated()
Browse files Browse the repository at this point in the history
Association's foreignKey doesn't get saved when saving hasMany associations since it's not in the model's whitelist after validation.
This happens if you don't send the foreignKey with the associated records data.
  • Loading branch information
clns committed Aug 30, 2012
1 parent fd2f3ae commit adb8142
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/Cake/Model/Model.php
Expand Up @@ -2266,6 +2266,10 @@ public function saveAssociated($data = null, $options = array()) {
$values[$i] = array_merge(array($key => $this->id), $value, array($key => $this->id));
}
}
// add foreignKey to whitelist if not already there
if (!in_array($key, $this->{$association}->whitelist)) {
$this->{$association}->whitelist[] = $key;
}
$_return = $this->{$association}->saveMany($values, array_merge($options, array('atomic' => false)));
if (in_array(false, $_return, true)) {
$validationErrors[$association] = $this->{$association}->validationErrors;
Expand Down

0 comments on commit adb8142

Please sign in to comment.