Remove default relationships from serializers

This commit is contained in:
Toby Zerner 2015-06-01 12:24:06 +09:30
parent 71a5b1f49c
commit 39e1b8e008
7 changed files with 5 additions and 40 deletions

View File

@ -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']
};
}

View File

@ -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.

View File

@ -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);
};
}

View File

@ -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.
*

View File

@ -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.
*

View File

@ -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.
*

View File

@ -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.
*