コード例 #1
0
 /**
  * @inheritdoc
  */
 public function getRelationships($post, array $includeRelationships = [])
 {
     /** @var Post $post */
     // that's an example how $includeRelationships could be used for reducing requests to database
     if (isset($includeRelationships['author']) === true) {
         // as author will be included as full resource we have to give full resource
         $author = $post->author;
     } else {
         // as author will be included as just id and type so it's not necessary to load it from database
         $author = new Author();
         $author->setAttribute($author->getKeyName(), $post->author_id);
     }
     return ['author' => [self::DATA => $author], 'comments' => [self::DATA => $post->comments->all()]];
 }