Jump to:

11002 Posts in 2734 Topics by 1823 members

All other Modules

SilverStripe Forums » All other Modules » Restfulserver relationdepth not working?

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1670 Views
  • eddieconnecti
    Community Member
    26 Posts

    Restfulserver relationdepth not working? Link to this post

    Created a class "Promotion" extending "DataObject" and set $api_access = true. I now have some has_one relations, like below:

    class Promotion extends DataObject

       static $api_access = true;

       public static $has_one = array(
          "TeaserImage" => "Reference_TeaserImage",
          "Themenseite" => "Page"


    I would now like to call this page via Restful-Server, so I typed:

    As from here it works fine. I get data like this

    <DataObjectSet totalSize="4">
    <Promotion href="http://localhost/silverstripe/api/v1/Promotion/1.xml">
    <Themenseite linktype="has_one" href="http://localhost/silverstripe/api/v1/Page/6.xml" id="6"/>
    <Promotion href="http://localhost/silverstripe/api/v1/Promotion/2.xml">

    As you can see, I can not recieve the location / filename of the TeaserImage, and not the URLSegment of the linked Page. There is a URL Parameter called "relationdepth" in the RestfulServer, but it has no effect to the result.

    Can anyone tell me, how I can get the dataobject with image path and path to the linked page within one request?


  • Willr
    Forum Moderator
    5511 Posts

    Re: Restfulserver relationdepth not working? Link to this post

    relationdepth only shows links to related objects AFAIK. I'm pretty sure you have to make multiple calls to get the data from related objects.

  • priithansen
    Community Member
    25 Posts

    Re: Restfulserver relationdepth not working? Link to this post

    Old question I know but found this thread via google while searching for the same thing and maybe someone will find it usefull.

    The way I solved this problem:

    public static $has_one = array(
       'Thumbnail' => 'Image',

    public static $api_access = array(
       'view' => array('ThumbnailURL')

    public function getThumbnailURL() {
       if($this->ThumbnailID) {
          return $this->Thumbnail()->URL;
       else {
          return 0;

  • Mojo5000
    Community Member
    5 Posts

    Re: Restfulserver relationdepth not working? Link to this post

    Sry guys - I know this post is old, but the problem still exists.

    I know I'm sounding grumpy, but having to hand code every property for a relation kind of eliminates the point of having a service that should know how to serialize a slightly more than simple DataObject model that contains relations.

    There is still not a decent RESTful API for Silverstripe that works seamlessly like almost every other framework out there.

    Is this in the SS roadmap or are we going to have to work out this key functionality? The existing one looks like it was extracted from the 2.4 core and left to dangle on its own. Curious why this was done.

    Thoughts? Solutions?

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.