mirror of
https://github.com/silverstripe/silverstripe-restfulserver
synced 2024-10-22 12:05:58 +00:00
Ensure that we can GET has_many relations
This commit is contained in:
parent
db4a70673b
commit
6dc4e0bd5b
@ -509,9 +509,9 @@ class RestfulServer extends Controller {
|
|||||||
protected function getObjectRelationQuery($obj, $params, $sort, $limit, $relationName) {
|
protected function getObjectRelationQuery($obj, $params, $sort, $limit, $relationName) {
|
||||||
// The relation method will return a DataList, that getSearchQuery subsequently manipulates
|
// The relation method will return a DataList, that getSearchQuery subsequently manipulates
|
||||||
if($obj->hasMethod($relationName)) {
|
if($obj->hasMethod($relationName)) {
|
||||||
if($relationClass = $obj->has_one($relationName)) {
|
if($obj->has_one($relationName) || $obj->has_many($relationName)) {
|
||||||
$joinField = $relationName . 'ID';
|
$relationClass = $obj->has_one($relationName) ? $obj->has_one($relationName) : $obj->has_many($relationName);
|
||||||
$list = DataList::create($relationClass)->byIDs(array($obj->$joinField));
|
$list = DataList::create($obj->ClassName)->relation($relationName)->forForeignID(array($obj->ID));
|
||||||
} else {
|
} else {
|
||||||
$list = $obj->$relationName();
|
$list = $obj->$relationName();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user