thephpleague / fractal

Output complex, flexible, AJAX/RESTful data structures.

Home Page:fractal.thephpleague.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Setting `withResourceName` results in an empty ParamBag for Includes.

PeterCat12 opened this issue · comments

When \League\Fractal\TransformerAbstract::callIncludeMethod calls the \League\Fractal\Scope::getIdentifier method the resulting identifier is "incorrect" IF \Spatie\Fractalistic\Fractal::withResourceName was called to set a "top level identifier". It's "incorrect" in the sense that \League\Fractal\Manager::getIncludeParams method has no entry for the resulting identifier.

Code example:

url: /api/v1/abcd/users/36?include=comments:status_in(deleted)

... 
return fractal($user, $transformer, new JsonApiSerializer($base_url))
                ->withResourceName('abcd-users')
                ->respond($status, $headers);

Then in \League\Fractal\TransformerAbstract::callIncludeMethod

protected function callIncludeMethod(Scope $scope, $includeName, $data)
    {
        $scopeIdentifier = $scope->getIdentifier($includeName);
        // resulting `$scopeIdentifer` is `abcd-users.comments`
        $params = $scope->getManager()->getIncludeParams($scopeIdentifier);
        // `$params` is empty as the manager only has `includeParams` for `comments` (not `abcd-users.comments`).
       ... 
} 

Closed as I think the issue better belongs to be opened in the Spatie\Fractalistic\Fractal repo:
spatie/fractalistic#49