Skip to content

Support to-many relations in included resources. #84

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

Merged
merged 6 commits into from
Mar 13, 2017

Conversation

HennerM
Copy link
Contributor

@HennerM HennerM commented Oct 9, 2016

I noticed an issue while using your awesome library.

It's currently not possible to include "to-many" relations that are defined in included resources. For example if you have Post and Comment objects like in your unit tests and you want to include an array of "likes" in the Comment object, these aren't included in the result.

Because this is my first pull request, I welcome all kinds of critique. ;)

@HennerM
Copy link
Contributor Author

HennerM commented Oct 23, 2016

Any updates on this one? It looks like this is also the cause for nilportugues/laravel5-jsonapi#39.

$existingIndex = self::findIncludedIndex($data[JsonApiTransformer::INCLUDED_KEY], $arrayData[JsonApiTransformer::ID_KEY], $arrayData[JsonApiTransformer::TYPE_KEY]);
}
if ($existingIndex !== false) {
$data[JsonApiTransformer::INCLUDED_KEY][$existingIndex] = \array_filter(\array_merge($data[JsonApiTransformer::INCLUDED_KEY][$existingIndex],

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opening parenthesis of a multi-line function call must be the last content on the line

}
if ($existingIndex !== false) {
$data[JsonApiTransformer::INCLUDED_KEY][$existingIndex] = \array_filter(\array_merge($data[JsonApiTransformer::INCLUDED_KEY][$existingIndex],
\array_filter($arrayData, self::filterEmptyArray())), self::filterEmptyArray());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Multi-line function call not indented correctly; expected 20 spaces but found 24
  • Closing parenthesis of a multi-line function call must be on a line by itself

if (!empty($data[JsonApiTransformer::INCLUDED_KEY])) {
$data[JsonApiTransformer::INCLUDED_KEY] = \array_values(
\array_unique($data[JsonApiTransformer::INCLUDED_KEY], SORT_REGULAR)
);
}
}

protected static function filterEmptyArray()
{
return function($value) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected 1 space after FUNCTION keyword; 0 found

@nilportugues nilportugues merged commit f2c6772 into nilportugues:master Mar 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants