7921 Posts in 1359 Topics by 933 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » Restfulserver relationdepth not working?
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 1156 Views |
-
Restfulserver relationdepth not working?

21 May 2010 at 2:10am Last edited: 21 May 2010 2:10am
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:
http://localhost/silverstripe/api/v1/promotionAs from here it works fine. I get data like this
<DataObjectSet totalSize="4">
<Promotion href="http://localhost/silverstripe/api/v1/Promotion/1.xml">
<TeaserImageID>0</TeaserImageID>
<ThemenseiteID>6</ThemenseiteID>
<ID>1</ID>
<Themenseite linktype="has_one" href="http://localhost/silverstripe/api/v1/Page/6.xml" id="6"/>
</Promotion>
<Promotion href="http://localhost/silverstripe/api/v1/Promotion/2.xml">
....
</Promotion>
</DataObjectSet>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?
Thanks!
-
Re: Restfulserver relationdepth not working?

21 May 2010 at 8:50pm
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.
-
Re: Restfulserver relationdepth not working?

14 December 2012 at 5:54am
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;
}
}
| 1156 Views | ||
|
Page:
1
|
Go to Top |


