Skip to content

Commit

Permalink
fixed bug where checkboxReleation id have not been delivered closes #323
Browse files Browse the repository at this point in the history
  • Loading branch information
nadar committed Aug 10, 2015
1 parent c0e43be commit 1c4b967
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions modules/admin/ngrest/plugins/CheckboxRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit 1c4b967

Please sign in to comment.