mirror of
https://github.com/flarum/framework.git
synced 2024-12-13 07:03:35 +08:00
Remove default relationships from serializers
This commit is contained in:
parent
71a5b1f49c
commit
39e1b8e008
|
@ -54,7 +54,7 @@ export default class DiscussionPage extends mixin(Component, evented) {
|
|||
params() {
|
||||
return {
|
||||
near: this.currentNear,
|
||||
include: ['posts', 'posts.user']
|
||||
include: ['posts', 'posts.user', 'posts.user.groups']
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ class ShowAction extends SerializeResourceAction
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $link = ['posts'];
|
||||
public static $link = ['posts', 'posts.discussion'];
|
||||
|
||||
/**
|
||||
* The fields that are available to be sorted by.
|
||||
|
|
|
@ -49,12 +49,12 @@ abstract class BaseSerializer extends SerializerAbstract
|
|||
$relation = $caller['function'];
|
||||
}
|
||||
|
||||
return function ($model, $include, $links) use ($serializer, $many, $relation) {
|
||||
return function ($model, $include, $included, $links) use ($serializer, $many, $relation) {
|
||||
if ($relation instanceof Closure) {
|
||||
$data = $relation($model, $include);
|
||||
} else {
|
||||
if ($include) {
|
||||
$data = !is_null($model->$relation) ? $model->$relation : ($many ? $model->$relation()->get() : $model->$relation()->first());
|
||||
$data = !is_null($model->$relation) ? $model->$relation : $model->$relation()->getResults();
|
||||
} elseif ($many) {
|
||||
$relationIds = $relation.'_ids';
|
||||
$data = $model->$relationIds ?: $model->$relation()->get(['id'])->fetch('id')->all();
|
||||
|
@ -67,7 +67,7 @@ abstract class BaseSerializer extends SerializerAbstract
|
|||
if ($serializer instanceof Closure) {
|
||||
$serializer = $serializer($model, $data);
|
||||
}
|
||||
$serializer = new $serializer($this->actor, $links);
|
||||
$serializer = new $serializer($this->actor, $included, $links);
|
||||
return $many ? $serializer->collection($data) : $serializer->resource($data);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -2,13 +2,6 @@
|
|||
|
||||
class DiscussionSerializer extends DiscussionBasicSerializer
|
||||
{
|
||||
/**
|
||||
* Default relations to include.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $include = ['startUser', 'lastUser'];
|
||||
|
||||
/**
|
||||
* Serialize attributes of a Discussion model for JSON output.
|
||||
*
|
||||
|
|
|
@ -9,20 +9,6 @@ class PostBasicSerializer extends BaseSerializer
|
|||
*/
|
||||
protected $type = 'posts';
|
||||
|
||||
/**
|
||||
* Default relations to link.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $link = ['discussion'];
|
||||
|
||||
/**
|
||||
* Default relations to include.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $include = ['user'];
|
||||
|
||||
/**
|
||||
* Serialize attributes of a Post model for JSON output.
|
||||
*
|
||||
|
|
|
@ -2,13 +2,6 @@
|
|||
|
||||
class PostSerializer extends PostBasicSerializer
|
||||
{
|
||||
/**
|
||||
* Default relations to include.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $include = ['user', 'editUser', 'hideUser'];
|
||||
|
||||
/**
|
||||
* Serialize attributes of a Post model for JSON output.
|
||||
*
|
||||
|
|
|
@ -2,13 +2,6 @@
|
|||
|
||||
class UserSerializer extends UserBasicSerializer
|
||||
{
|
||||
/**
|
||||
* Default relations to include.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $include = ['groups'];
|
||||
|
||||
/**
|
||||
* Serialize attributes of a User model for JSON output.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue
Block a user