Skip to content

Commit 8e42588

Browse files
committed
Fixes extracting key values for viaTable relationships
1 parent 84ef416 commit 8e42588

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Yii LinkMany Change Log
22
=======================
33

4+
1.1.0 under development
5+
-----------------------
6+
7+
- Fixes extracting key values for `viaTable` relationships
8+
49
1.1.0 Jan 18, 2022
510
------------------
611

composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,10 @@
4848
"branch-alias": {
4949
"dev-master": "1.0.x-dev"
5050
}
51+
},
52+
"config": {
53+
"allow-plugins": {
54+
"yiisoft/yii2-composer": true
55+
}
5156
}
5257
}

src/LinkManyBehavior.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,16 @@ protected function fillRelation($model, $data, $formName)
333333
protected function extractPrimaryKey($data, $relation)
334334
{
335335
if ($relation->via) {
336-
return $data;
336+
if (is_scalar($data)) {
337+
return $data;
338+
}
339+
340+
$result = [];
341+
foreach ($relation->via->link as $key => $value) {
342+
$result[] = $data[$value];
343+
}
344+
345+
return count($result) === 1 ? $result[0] : $result;
337346
} else {
338347
$modelClass = $relation->modelClass;
339348
$primaryKey = $modelClass::primaryKey();

0 commit comments

Comments
 (0)