Properly include to-many relations

This commit is contained in:
Toby Zerner 2015-05-14 22:35:31 +09:30
parent c5420ef7df
commit 9e81e9f955

View File

@ -54,7 +54,7 @@ abstract class BaseSerializer extends SerializerAbstract
$data = $relation($model, $include);
} else {
if ($include) {
$data = !is_null($model->$relation) ? $model->$relation : $model->$relation()->first();
$data = !is_null($model->$relation) ? $model->$relation : ($many ? $model->$relation()->get() : $model->$relation()->first());
} elseif ($many) {
$relationIds = $relation.'_ids';
$data = $model->$relationIds ?: $model->$relation()->get(['id'])->fetch('id')->all();