Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions src/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Api
/** @var string Request path */
public $path;


/**
* Reads everything off globals.
*
Expand Down Expand Up @@ -178,7 +179,7 @@ protected function call($callable, $vars = [])
*/
protected function exportModel(\atk4\data\Model $m)
{
return $m->export($this->getAllowedFields($m, 'read'));
return $m->export($this->getAllowedFields($m, 'read'), null, false);
}

/**
Expand Down Expand Up @@ -405,12 +406,26 @@ public function rest($pattern, $model = null, $methods = null)
$model = $this->call($model, $args);
}

// limit fields
$model->onlyFields($this->getAllowedFields($model, 'read'));
$this->loadModelByValue($model, $id);

//calculate only once
$allowed_fields = $this->getAllowedFields($model, 'read');
$data = [];
// get all field-elements
foreach ($model->elements as $field => $f) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No this is wrong now. Should use $model->getFields() and that way get rid of instanceof \atk4\data\Field condition and as result this change can be made simpler.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also tests fail.

//only use allowed fields
if(!in_array($field, $allowed_fields)) {
continue;
}

if ($f instanceof \atk4\data\Field) {
$data[$field] = $f->toString();
}
}

// load model and get field values
return $this->loadModelByValue($model, $id)->get();
return $data;
};

$this->get($pattern.'/:id', $f);
}

Expand Down