Skip to content

parseIncludes ignores sparse field set on included data #498

@nivv

Description

@nivv

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions