From 6dc4e0bd5bb290dd3b326bc4f6961f9cbe8776a7 Mon Sep 17 00:00:00 2001 From: Jason Darwin Date: Thu, 17 Apr 2014 16:03:21 +1200 Subject: [PATCH] Ensure that we can GET has_many relations --- code/RestfulServer.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/code/RestfulServer.php b/code/RestfulServer.php index 4ecb8de..c7acbae 100644 --- a/code/RestfulServer.php +++ b/code/RestfulServer.php @@ -509,9 +509,9 @@ class RestfulServer extends Controller { protected function getObjectRelationQuery($obj, $params, $sort, $limit, $relationName) { // The relation method will return a DataList, that getSearchQuery subsequently manipulates if($obj->hasMethod($relationName)) { - if($relationClass = $obj->has_one($relationName)) { - $joinField = $relationName . 'ID'; - $list = DataList::create($relationClass)->byIDs(array($obj->$joinField)); + if($obj->has_one($relationName) || $obj->has_many($relationName)) { + $relationClass = $obj->has_one($relationName) ? $obj->has_one($relationName) : $obj->has_many($relationName); + $list = DataList::create($obj->ClassName)->relation($relationName)->forForeignID(array($obj->ID)); } else { $list = $obj->$relationName(); }