From 98039144984eab4e43be7316ecc29fc56959b2c3 Mon Sep 17 00:00:00 2001 From: lubo Date: Mon, 25 Mar 2019 18:04:31 +0800 Subject: [PATCH] bugfix when posts is not needed when showing discussion (#17) When accessing /api/discussion/[id]?include=user, NOTICE occurs --- src/Listener/AddPostFlagsRelationship.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Listener/AddPostFlagsRelationship.php b/src/Listener/AddPostFlagsRelationship.php index e0d2c5b..62b2d9f 100755 --- a/src/Listener/AddPostFlagsRelationship.php +++ b/src/Listener/AddPostFlagsRelationship.php @@ -100,7 +100,9 @@ public function prepareApiData(WillSerializeData $event) // models) so that we can selectively expose only the flags that the // user has permission to view. if ($event->isController(Controller\ShowDiscussionController::class)) { - $posts = $event->data->getRelation('posts'); + if ($event->data->relationLoaded('posts')) { + $posts = $event->data->getRelation('posts'); + } } if ($event->isController(Controller\ListPostsController::class)) {