mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX Fixed many_many relations querying in RestfulServer
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@81346 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
c389c01f9c
commit
e54a2e75e6
@ -508,6 +508,8 @@ class RestfulServer extends Controller {
|
|||||||
$query = $obj->{"{$relationName}Query"}(null, $sort, null, $limit);
|
$query = $obj->{"{$relationName}Query"}(null, $sort, null, $limit);
|
||||||
$relationClass = $obj->{"{$relationName}Class"}();
|
$relationClass = $obj->{"{$relationName}Class"}();
|
||||||
} elseif($relationClass = $obj->many_many($relationName)) {
|
} elseif($relationClass = $obj->many_many($relationName)) {
|
||||||
|
// many_many() returns different notation
|
||||||
|
$relationClass = $relationClass[1];
|
||||||
$query = $obj->getManyManyComponentsQuery($relationName);
|
$query = $obj->getManyManyComponentsQuery($relationName);
|
||||||
} elseif($relationClass = $obj->has_many($relationName)) {
|
} elseif($relationClass = $obj->has_many($relationName)) {
|
||||||
$query = $obj->getComponentsQuery($relationName);
|
$query = $obj->getComponentsQuery($relationName);
|
||||||
|
@ -91,6 +91,23 @@ class RestfulServerTest extends SapphireTest {
|
|||||||
$this->assertEquals($ratingsArr[1]['@attributes']['id'], $rating2->ID);
|
$this->assertEquals($ratingsArr[1]['@attributes']['id'], $rating2->ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGETManyManyRelationshipsXML() {
|
||||||
|
// author4 has related authors author2 and author3
|
||||||
|
$author2 = $this->objFromFixture('RestfulServerTest_Author', 'author2');
|
||||||
|
$author3 = $this->objFromFixture('RestfulServerTest_Author', 'author3');
|
||||||
|
$author4 = $this->objFromFixture('RestfulServerTest_Author', 'author4');
|
||||||
|
|
||||||
|
$url = "/api/v1/RestfulServerTest_Author/" . $author4->ID . '/RelatedAuthors';
|
||||||
|
$response = Director::test($url, null, null, 'GET');
|
||||||
|
$this->assertEquals($response->getStatusCode(), 200);
|
||||||
|
$arr = Convert::xml2array($response->getBody());
|
||||||
|
$authorsArr = $arr['RestfulServerTest_Author'];
|
||||||
|
|
||||||
|
$this->assertEquals(count($authorsArr), 2);
|
||||||
|
$this->assertEquals($authorsArr[0]['ID'], $author2->ID);
|
||||||
|
$this->assertEquals($authorsArr[1]['ID'], $author3->ID);
|
||||||
|
}
|
||||||
|
|
||||||
public function testPUTWithFormEncoded() {
|
public function testPUTWithFormEncoded() {
|
||||||
$_SERVER['PHP_AUTH_USER'] = 'editor@test.com';
|
$_SERVER['PHP_AUTH_USER'] = 'editor@test.com';
|
||||||
$_SERVER['PHP_AUTH_PW'] = 'editor';
|
$_SERVER['PHP_AUTH_PW'] = 'editor';
|
||||||
@ -410,6 +427,7 @@ class RestfulServerTest_Author extends DataObject implements TestOnly {
|
|||||||
|
|
||||||
static $many_many = array(
|
static $many_many = array(
|
||||||
'RelatedPages' => 'RestfulServerTest_Page',
|
'RelatedPages' => 'RestfulServerTest_Page',
|
||||||
|
'RelatedAuthors' => 'RestfulServerTest_Author',
|
||||||
);
|
);
|
||||||
|
|
||||||
static $has_many = array(
|
static $has_many = array(
|
||||||
|
@ -43,6 +43,13 @@ RestfulServerTest_Comment:
|
|||||||
RestfulServerTest_Author:
|
RestfulServerTest_Author:
|
||||||
author1:
|
author1:
|
||||||
FirstName: Author 1
|
FirstName: Author 1
|
||||||
|
author2:
|
||||||
|
FirstName: Author 2
|
||||||
|
author3:
|
||||||
|
Firstname: Author 3
|
||||||
|
author4:
|
||||||
|
FirstName: Author 4
|
||||||
|
RelatedAuthors: =>RestfulServerTest_Author.author2,=>RestfulServerTest_Author.author3
|
||||||
RestfulServerTest_AuthorRating:
|
RestfulServerTest_AuthorRating:
|
||||||
rating1:
|
rating1:
|
||||||
Rating: 3
|
Rating: 3
|
||||||
|
Loading…
Reference in New Issue
Block a user