Browse Source

Fixes error loading `hasMany` relation without referenced key in data

tags/1.6.0
leandrogehlen 6 years ago
parent
commit
b7b67ebcb3
  1. 2
      src/SaveRelationsBehavior.php

2
src/SaveRelationsBehavior.php

@ -241,7 +241,7 @@ class SaveRelationsBehavior extends Behavior
$fks[$modelAttribute] = $data[$modelAttribute]; $fks[$modelAttribute] = $data[$modelAttribute];
} elseif ($relation->multiple && !$relation->via) { } elseif ($relation->multiple && !$relation->via) {
foreach ($link as $relatedAttribute => $relatedModelAttribute) { foreach ($link as $relatedAttribute => $relatedModelAttribute) {
if (!isset($data[$relatedAttribute])) { if (!isset($data[$relatedAttribute]) && in_array($relatedAttribute, $modelClass::primaryKey())) {
$fks[$relatedAttribute] = $this->owner->{$relatedModelAttribute}; $fks[$relatedAttribute] = $this->owner->{$relatedModelAttribute};
} }
} }

Loading…
Cancel
Save