mirror of
https://github.com/flarum/framework.git
synced 2024-11-25 09:41:49 +08:00
Properly include to-many relations
This commit is contained in:
parent
c5420ef7df
commit
9e81e9f955
|
@ -54,7 +54,7 @@ abstract class BaseSerializer extends SerializerAbstract
|
||||||
$data = $relation($model, $include);
|
$data = $relation($model, $include);
|
||||||
} else {
|
} else {
|
||||||
if ($include) {
|
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) {
|
} elseif ($many) {
|
||||||
$relationIds = $relation.'_ids';
|
$relationIds = $relation.'_ids';
|
||||||
$data = $model->$relationIds ?: $model->$relation()->get(['id'])->fetch('id')->all();
|
$data = $model->$relationIds ?: $model->$relation()->get(['id'])->fetch('id')->all();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user