Skip to content

added sorting based upon belongsTo relationship attribute #161

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

Closed
wants to merge 1 commit into from
Closed

added sorting based upon belongsTo relationship attribute #161

wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Oct 5, 2016

No description provided.

@lindyhopchris
Copy link
Collaborator

@neomerx I'm not sure about this. The spec says:

Note: It is recommended that dot-separated sort fields be used to request sorting based upon relationship attributes.

However, that doesn't mean an application has to be following that recommendation. For instance, if you have nested attributes, then you could be using the dot notation to denote sorting by a nested attribute.

I.e. this is an application concern rather than a library concern. If the sort field is author.name then it's down to the application to decide what to do with that sort field, but it'd still expect to get the full author.name string from SortParameterInterface::getField()

@ghost
Copy link
Author

ghost commented Oct 5, 2016

i am not sure whether it should be put into the library.
i am not managed to handle the dot notation in application.
as the parser has already throw exception if i do not edit the parse -> getsortparameter method.

@lindyhopchris
Copy link
Collaborator

Interesting. What exception are you getting?

@ghost
Copy link
Author

ghost commented Oct 5, 2016

  1. Tests\UsersTest::testIndexWithParameters
    Neomerx\JsonApi\Exceptions\JsonApiException: JSON API error

@ghost
Copy link
Author

ghost commented Oct 5, 2016

the test:

public function testIndexWithParameters()
{
$queryParams = [
'sort' => '-role.name',
];
$response = $this->get(self::API_URI, $queryParams);

    $this->assertEquals(200, $response->getStatusCode());
    $this->assertNotNull($resources = json_decode((string)$response->getBody()));
}

@lindyhopchris
Copy link
Collaborator

What's the stack trace for the Exception - i.e. where is it being thrown from?

@ghost
Copy link
Author

ghost commented Oct 6, 2016

#0 /hosts/test25/vendor/limoncello-php/json-api/src/Http/BaseController.php(68): Limoncello\JsonApi\Http\BaseController::mapQueryParameters(Object(Limoncello\ContainerLight\Container), Object(Neomerx\JsonApi\Encoder\Parameters\EncodingParameters), 'App\Schemes\Use...')
#1 [internal function]: Limoncello\JsonApi\Http\BaseController::index(Array, Object(Limoncello\ContainerLight\Container), Object(Zend\Diactoros\ServerRequest))
#2 /hosts/test25/vendor/limoncello-php/core/src/Application/Application.php(304): call_user_func(Array, Array, Object(Limoncello\ContainerLight\Container), Object(Zend\Diactoros\ServerRequest))
#3 /hosts/test25/app/Authentication/Middleware/TokenAuthentication.php(48): Limoncello\Core\Application\Application->Limoncello\Core\Application{closure}(Object(Zend\Diactoros\ServerRequest))
#4 [internal function]: App\Authentication\Middleware\TokenAuthentication::handle(Object(Zend\Diactoros\ServerRequest), Object(Closure), Object(Limoncello\ContainerLight\Container))
#5 /hosts/test25/vendor/limoncello-php/core/src/Application/Application.php(362): call_user_func('App\Http\Middle...', Object(Zend\Diactoros\ServerRequest), Object(Closure), Object(Limoncello\ContainerLight\Container))
#6 /hosts/test25/vendor/limoncello-php/json-api/src/Http/Cors/CorsMiddleware.php(49): Limoncello\Core\Application\Application->Limoncello\Core\Application{closure}(Object(Zend\Diactoros\ServerRequest))
#7 [internal function]: Limoncello\JsonApi\Http\Cors\CorsMiddleware::handle(Object(Zend\Diactoros\ServerRequest), Object(Closure), Object(Limoncello\ContainerLight\Container))
#8 /hosts/test25/vendor/limoncello-php/core/src/Application/Application.php(362): call_user_func('App\Http\Middle...', Object(Zend\Diactoros\ServerRequest), Object(Closure), Object(Limoncello\ContainerLight\Container))
#9 /hosts/test25/vendor/limoncello-php/core/src/Application/Application.php(172): Limoncello\Core\Application\Application->Limoncello\Core\Application{closure}(Object(Zend\Diactoros\ServerRequest))
#10 /hosts/test25/tests/AppWrapper.php(73): Limoncello\Core\Application\Application->handleRequest(Object(Closure), Object(Zend\Diactoros\ServerRequest))
#11 /hosts/test25/vendor/limoncello-php/core/src/Application/Application.php(132): Tests\AppWrapper->handleRequest(Object(Closure), Object(Zend\Diactoros\ServerRequest))
#12 /hosts/test25/vendor/limoncello-php/testing/src/PhpUnitTestCase.php(96): Limoncello\Core\Application\Application->run()
#13 /hosts/test25/vendor/limoncello-php/testing/src/PhpUnitTestCase.php(115): Limoncello\Testing\PhpUnitTestCase->call('GET', '/api/v1/users', Array, Array, Array, Array)
#14 /hosts/test25/tests/UsersTest.php(34): Limoncello\Testing\PhpUnitTestCase->get('/api/v1/users', Array)
#15 [internal function]: Tests\UsersTest->testIndexWithParameters()
#16 /hosts/test25/vendor/phpunit/phpunit/src/Framework/TestCase.php(1085): ReflectionMethod->invokeArgs(Object(Tests\UsersTest), Array)
#17 /hosts/test25/vendor/phpunit/phpunit/src/Framework/TestCase.php(936): PHPUnit_Framework_TestCase->runTest()
#18 /hosts/test25/vendor/phpunit/phpunit/src/Framework/TestResult.php(701): PHPUnit_Framework_TestCase->runBare()
#19 /hosts/test25/vendor/phpunit/phpunit/src/Framework/TestCase.php(892): PHPUnit_Framework_TestResult->run(Object(Tests\UsersTest))
#20 /hosts/test25/vendor/phpunit/phpunit/src/Framework/TestSuite.php(753): PHPUnit_Framework_TestCase->run(Object(PHPUnit_Framework_TestResult))
#21 /hosts/test25/vendor/phpunit/phpunit/src/Framework/TestSuite.php(753): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))
#22 /hosts/test25/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(465): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))
#23 /hosts/test25/vendor/phpunit/phpunit/src/TextUI/Command.php(185): PHPUnit_TextUI_TestRunner->doRun(Object(PHPUnit_Framework_TestSuite), Array, true)
#24 /hosts/test25/vendor/phpunit/phpunit/src/TextUI/Command.php(115): PHPUnit_TextUI_Command->run(Array, true)
#25 /hosts/test25/vendor/phpunit/phpunit/phpunit(47): PHPUnit_TextUI_Command::main()
#26 {main}

@lindyhopchris
Copy link
Collaborator

Hmmm... I think this is a Limencello problem rather than a problem with this base package.

@neomerx are you able to help?

@neomerx
Copy link
Owner

neomerx commented Oct 6, 2016

@ngantingon Sorry If I didn't give enough 'instructions' how to start the feature. Here they are https://github.com/limoncello-php/json-api/issues/33

@neomerx neomerx closed this Oct 6, 2016
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