|
|
@ -168,22 +168,31 @@ class SaveRelationsBehavior extends Behavior |
|
|
|
if (is_array($data)) { |
|
|
|
if (is_array($data)) { |
|
|
|
$fks = []; |
|
|
|
$fks = []; |
|
|
|
|
|
|
|
|
|
|
|
// Get the right link definition |
|
|
|
// search PK |
|
|
|
if ($relation->via instanceof BaseActiveRecord) { |
|
|
|
foreach($modelClass::primaryKey() as $modelAttribute) { |
|
|
|
$viaQuery = $relation->via; |
|
|
|
|
|
|
|
$link = $viaQuery->link; |
|
|
|
|
|
|
|
} elseif (is_array($relation->via)) { |
|
|
|
|
|
|
|
list($viaName, $viaQuery) = $relation->via; |
|
|
|
|
|
|
|
$link = $viaQuery->link; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
$link = $relation->link; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($link as $relatedAttribute => $modelAttribute) { |
|
|
|
|
|
|
|
if (array_key_exists($modelAttribute, $data) && !empty($data[$modelAttribute])) { |
|
|
|
if (array_key_exists($modelAttribute, $data) && !empty($data[$modelAttribute])) { |
|
|
|
$fks[$modelAttribute] = $data[$modelAttribute]; |
|
|
|
$fks[$modelAttribute] = $data[$modelAttribute]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!$fks) { |
|
|
|
|
|
|
|
// Get the right link definition |
|
|
|
|
|
|
|
if ($relation->via instanceof BaseActiveRecord) { |
|
|
|
|
|
|
|
$viaQuery = $relation->via; |
|
|
|
|
|
|
|
$link = $viaQuery->link; |
|
|
|
|
|
|
|
} elseif (is_array($relation->via)) { |
|
|
|
|
|
|
|
list($viaName, $viaQuery) = $relation->via; |
|
|
|
|
|
|
|
$link = $viaQuery->link; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
$link = $relation->link; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($link as $relatedAttribute => $modelAttribute) { |
|
|
|
|
|
|
|
if (array_key_exists($modelAttribute, $data) && !empty($data[$modelAttribute])) { |
|
|
|
|
|
|
|
$fks[$modelAttribute] = $data[$modelAttribute]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
$fks = $data; |
|
|
|
$fks = $data; |
|
|
|
} |
|
|
|
} |
|
|
|