thephpleague / fractal

Output complex, flexible, AJAX/RESTful data structures.

Home Page:fractal.thephpleague.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

parseIncludes ignores sparse field set on included data

nivv opened this issue · comments

I'm trying to figure out how to specify which fields to select when including a resource. But I can't get it to work. I've been looking through the Manager-class and I found this:

fractal/src/Manager.php

Lines 194 to 214 in a38f0b7

// Matches multiple instances of 'something(foo|bar|baz)' in the string
// I guess it ignores : so you could use anything, but probably don't do that
preg_match_all('/([\w]+)(\(([^\)]+)\))?/', $allModifiersStr, $allModifiersArr);
// [0] is full matched strings...
$modifierCount = count($allModifiersArr[0]);
$modifierArr = [];
for ($modifierIt = 0; $modifierIt < $modifierCount; $modifierIt++) {
// [1] is the modifier
$modifierName = $allModifiersArr[1][$modifierIt];
// and [3] is delimited params
$modifierParamStr = $allModifiersArr[3][$modifierIt];
// Make modifier array key with an array of params as the value
$modifierArr[$modifierName] = explode($this->paramDelimiter, $modifierParamStr);
}
$this->includeParams[$includeName] = $modifierArr;

Request I'm sending

GET /api-endpoint/producers?include=owner(id|name)

I've also tried the below formats

GET /api-endpoint/producers?include=owner:fields(id|name)
GET /api-endpoint/producers?include=owner:field(id|name)

I found that syntax from another issue: #386

How is it supposed to work?

commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 4 weeks if no further activity occurs. Thank you for your contributions.