Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sparse fields filter relationships #249

Open
efinder2 opened this issue Apr 29, 2020 · 3 comments
Open

sparse fields filter relationships #249

efinder2 opened this issue Apr 29, 2020 · 3 comments

Comments

@efinder2
Copy link
Contributor

I've started implementing the sparse fieldsets in my application. At first I was surprised how easy it was to add the functionality to my app. Without included relationships is the result as expected. Problem is that the relationships aren't added if I use sparse fieldsets. These could be accomplished by adding the type name to the fieldsets array.

According to the tests this should be working:

$aFieldSets = [
	// Attributes and relationships that should be shown
	'employees'  => ['firstName', 'lastName'],
	'subsidiaries'  => ['name'],
]
$sJson = $this->getJsonEncoder()
		->withLinks($aLinks)
		->withMeta($metaData))
		->withFieldSets($aFieldSets)
		->withIncludedPaths(['subsidiaries'])
		->encodeData($oRecords);

Only if the Fieldset is changed to this, the related data is shown.

$aFieldSets = [
	// Attributes and relationships that should be shown
	'employees'  => ['firstName', 'lastName','subsidiaries'],
	'subsidiaries'  => ['name'],
]

Where could be the problem?

@efinder2
Copy link
Contributor Author

The same thing you do in the tests. According to the specification https://jsonapi.org/format/#fetching-sparse-fieldsets there is no need to do that.
Here a snippet from the class FieldSetFilter:77-81

$parentType = $position->getParentType();
if ($this->hasFilter($parentType) === true) {
    return isset($this->getAllowedFields($parentType)[$position->getParentRelationship()]);
}

It checks whether the name of the relationship type is named in the required fields. To be sepc conform this method should always return true imho.

@efinder2
Copy link
Contributor Author

I know there were a discussion on this topic in #105 and #134. In my opinion the example in the 1.0 spec requires my interpretion:

GET /articles?include=author&fields[articles]=title,body&fields[people]=name HTTP/1.1
Accept: application/vnd.api+json

There is no reference of the author or people in the requested fields. But I assume the author should be included. Otherwise this would be nonsense

@efinder2 efinder2 reopened this Apr 30, 2020
@efinder2
Copy link
Contributor Author

Wrong button on comment pressed 🙈

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants