From 1c4b967f164dae993cd20c34bcb0944f1243bf73 Mon Sep 17 00:00:00 2001 From: nadar Date: Mon, 10 Aug 2015 10:46:21 +0200 Subject: [PATCH] fixed bug where checkboxReleation id have not been delivered closes #323 --- .../admin/ngrest/plugins/CheckboxRelation.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/modules/admin/ngrest/plugins/CheckboxRelation.php b/modules/admin/ngrest/plugins/CheckboxRelation.php index 53abc7e9b..a4c8e1a8c 100644 --- a/modules/admin/ngrest/plugins/CheckboxRelation.php +++ b/modules/admin/ngrest/plugins/CheckboxRelation.php @@ -44,13 +44,24 @@ public function __construct($model, $refJoinTable, $refModelPkId, $refJoinPkId, private function getOptionsData() { $items = []; - foreach ($this->model->find()->select($this->displayFields)->all() as $item) { + + $pk = $this->model->primaryKey(); + $pkName = reset($pk); + + $select = $this->displayFields; + $select[] = $pkName; + + foreach ($this->model->find()->select($select)->all() as $item) { + + $array = $item->toArray(); + unset($array[$pkName]); if ($this->displayTemplate) { - $label = vsprintf($this->displayTemplate, $item->toArray()); + $label = vsprintf($this->displayTemplate, $array); } else { - $label = implode(', ', $item->toArray()); + $label = implode(', ', $array); } - $items[] = ['id' => $item->id, 'label' => $label]; + + $items[] = ['id' => $item[$pkName], 'label' => $label]; } return ['items' => $items];