src/Resources/BaseDbTableResource.php
protected function retrieveRelatedRecords(TableSchema $schema, $relations, $requests, &$data, $refresh = false)
    {
        $relatedExtras = [
            ApiOptions::LIMIT   => $this->getMaxRecordsReturnedLimit(),
            ApiOptions::FIELDS  => ApiOptions::FIELDS_ALL,
            ApiOptions::REFRESH => $refresh
        ];
        foreach ($relations as $key => $relation) {
            if (empty($relation)) {
                throw new BadRequestException("Empty relationship found.");
            }

            if (is_array($requests) && array_key_exists($key, $requests)) {
                $requests[$key][ApiOptions::REFRESH] = $refresh;
                $this->retrieveRelationRecords($schema, $relation, $data, $requests[$key]);
            } elseif ((ApiOptions::FIELDS_ALL == $requests) || $relation->alwaysFetch) {
                $this->retrieveRelationRecords($schema, $relation, $data, $relatedExtras);
            }
        }
    }
protected function retrieveRelatedRecords(TableSchema $schema, $relations, $requests, &$data, $refresh = false)
    {
        $relatedExtras = [
            ApiOptions::LIMIT   => $this->getMaxRecordsReturnedLimit(),
            ApiOptions::FIELDS  => ApiOptions::FIELDS_ALL,
            ApiOptions::REFRESH => $refresh
        ];
        foreach ($relations as $key => $relation) {
            if (empty($relation)) {
                throw new BadRequestException("Empty relationship found.");
            }

            if (is_array($requests) && array_key_exists($key, $requests)) {
                $requests[$key][ApiOptions::REFRESH] = $refresh;
                $this->retrieveRelationRecords($schema, $relation, $data, $requests[$key]);
            } elseif ((ApiOptions::FIELDS_ALL == $requests) || $relation->alwaysFetch) {
                $this->retrieveRelationRecords($schema, $relation, $data, $relatedExtras);
            }
        }
    }
@param TableSchema      $schema
@param RelationSchema[] $relations
@param string|array     $requests
@param array            $data
@param boolean          $refresh

@return void
@throws BadRequestException
@throws ForbiddenException
@throws InternalServerErrorException
@throws RestException