diff --git a/framework/core/src/Api/Controller/ListDiscussionsController.php b/framework/core/src/Api/Controller/ListDiscussionsController.php index ab8b21283..04db95c3a 100644 --- a/framework/core/src/Api/Controller/ListDiscussionsController.php +++ b/framework/core/src/Api/Controller/ListDiscussionsController.php @@ -93,6 +93,18 @@ class ListDiscussionsController extends AbstractCollectionController $results->areMoreResults() ? null : 0 ); - return $results->getResults(); + $results = $results->getResults(); + + if ($relations = array_intersect($load, ['startPost', 'lastPost'])) { + foreach ($results as $discussion) { + foreach ($relations as $relation) { + if ($discussion->$relation) { + $discussion->$relation->discussion = $discussion; + } + } + } + } + + return $results; } } diff --git a/framework/core/src/Api/Controller/ShowDiscussionController.php b/framework/core/src/Api/Controller/ShowDiscussionController.php index 7f04ca167..e99ec54b0 100644 --- a/framework/core/src/Api/Controller/ShowDiscussionController.php +++ b/framework/core/src/Api/Controller/ShowDiscussionController.php @@ -173,6 +173,12 @@ class ShowDiscussionController extends AbstractResourceController $query->orderBy('time')->skip($offset)->take($limit)->with($include); - return $query->get()->all(); + $posts = $query->get()->all(); + + foreach ($posts as $post) { + $post->discussion = $discussion; + } + + return $posts; } }