Skip to content
Browse files

Add foreignKey to whitelist in saveAssociated()

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...
1 parent fd2f3ae commit adb8142d2694692ec71a063ac2ad1b275f3a67c9 @clns clns committed
Showing with 4 additions and 0 deletions.
  1. +4 −0 lib/Cake/Model/Model.php
View
4 lib/Cake/Model/Model.php
@@ -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;

0 comments on commit adb8142

Please sign in to comment.
Something went wrong with that request. Please try again.